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 ¶
- func Contains(target, list interface{}) bool
- func ContainsInString(target string, list []string) bool
- func DecryptAnsibleVault(fileContent []byte, secret string) []byte
- func GetExtension(path string) (string, error)
- func HandlePanic(r any, errMessage string)
- func LineCounter(path string, fallbackMinifiedFileLOC int) (int, error)
- func MergeMaps(map1, map2 map[string]interface{})
- func NextRandom() string
- func ReadFileContentToUTF8(content []byte, filename string) ([]byte, error)
- func ReadFileToUTF8(path string) ([]byte, error)
- func SortedKeys(mapToSort map[string]string) []string
- func SplitLines(content string) *[]string
- func ValidateUUID(id string) bool
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 ¶
ContainsInString verifies if some string in list contains the specified target
func DecryptAnsibleVault ¶
DecryptAnsibleVault verifies if the fileContent is encrypted by ansible-vault. If yes, the function decrypts it
func GetExtension ¶
GetExtension gets the extension of a file path
func HandlePanic ¶
func LineCounter ¶
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 ReadFileContentToUTF8 ¶ added in v2.1.16
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
ReadFileToUTF8 reads a file and converts it to UTF-8 if needed.
func SortedKeys ¶
SortedKeys returns a sorted slice with all map keys
func ValidateUUID ¶
ValidateUUID checks if the given id is valid by the format UUID using regex expression
Types ¶
This section is empty.