utils

package
v2.1.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package utils contains various utility functions to use in other packages

Package utils contains various utility functions to use in other packages

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(target, list interface{}) bool

Contains if a function to check if list contains target

func ContainsInString

func ContainsInString(target string, list []string) bool

ContainsInString verifies if some string in list contains the specified target

func DecryptAnsibleVault

func DecryptAnsibleVault(fileContent []byte, secret string) []byte

DecryptAnsibleVault verifies if the fileContent is encrypted by ansible-vault. If yes, the function decrypts it

func GetExtension

func GetExtension(path string) (string, error)

GetExtension gets the extension of a file path

func HandlePanic

func HandlePanic(r any, errMessage string)

func LineCounter

func LineCounter(path string, fallbackMinifiedFileLOC int) (int, error)

LineCounter returns the number of lines in a file For files with a .json extension, if the file is detected as minified JSON, it will Beautifying the JSON and return the number of lines in the formatted output For all other files, or non-minified JSON, it returns the actual number of lines in the file If an error occurs reading the file, fallbackMinifiedFileLOC is returned for minified JSON files

func MergeMaps

func MergeMaps(map1, map2 map[string]interface{})

MergeMaps merges two maps

func NextRandom

func NextRandom() string

NextRandom returns a random number

func ReadFileContentToUTF8 added in v2.1.16

func ReadFileContentToUTF8(content []byte, filename string) ([]byte, error)

ReadFileContentToUTF8 converts file content to UTF-8 if needed. This is similar to ReadFileToUTF8 but works on already-read content. It handles UTF-16 LE/BE with BOM, and validates UTF-8. This is critical for files extracted from ZIP archives on Windows, which may be encoded as UTF-16 LE with BOM (0xFF 0xFE).

func ReadFileToUTF8 added in v2.1.16

func ReadFileToUTF8(path string) ([]byte, error)

ReadFileToUTF8 reads a file and converts it to UTF-8 if needed.

func SortedKeys

func SortedKeys(mapToSort map[string]string) []string

SortedKeys returns a sorted slice with all map keys

func SplitLines

func SplitLines(content string) *[]string

SplitLines splits the document by line

func ValidateUUID

func ValidateUUID(id string) bool

ValidateUUID checks if the given id is valid by the format UUID using regex expression

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL