Documentation
¶
Index ¶
- Variables
- func CleanArray(data []interface{}) []interface{}
- func CleanByte(b []byte) []byte
- func CleanJSON(val interface{}) interface{}
- func CleanMap(data map[string]interface{}) map[string]interface{}
- func CleanStr(str string) string
- func CloseWatchers(root string)
- func CompareHash(text []byte, compare []byte, key []byte) bool
- func Compress(msg []byte) ([]byte, error)
- func Contains[T any](search []T, value T) bool
- func ContainsMap[T Hashable, J any](search map[T]J, value J) bool
- func ContainsMapKey[T Hashable, J any](search map[T]J, key T) bool
- func DecodeJSON(data io.Reader) (map[string]interface{}, error)
- func Decompress(str []byte) ([]byte, error)
- func Decrypt(text []byte, key []byte) ([]byte, error)
- func DecryptLocal(ciphertext []byte, key []byte) ([]byte, error)
- func DeepCopyJson(data map[string]interface{}) (map[string]interface{}, error)
- func Encrypt(text []byte, key []byte) ([]byte, error)
- func EncryptLocal(text []byte, key []byte) ([]byte, error)
- func EscapeHTML(html []byte) []byte
- func EscapeHTMLArgs(html []byte, quote ...byte) []byte
- func FormatMemoryUsage(b uint64) float64
- func GetFileFromParent(root string, start string, search string) (string, bool)
- func GetLinuxInstaller(man []string) string
- func HasLinuxPkg(pkg []string) bool
- func IndexOf[T any](search []T, value T) (int, error)
- func IndexOfMap[T Hashable, J any](search map[T]J, value J) (T, error)
- func InstallLinuxPkg(pkg []string, man ...string)
- func IsZeroOfUnderlyingType(x interface{}) bool
- func JoinPath(path ...string) (string, error)
- func MapArgs(args ...[]string) map[string]string
- func MapArgsByte(args ...[][]byte) map[string][]byte
- func NewHash(text []byte, key []byte) ([]byte, error)
- func ParseJson(b []byte) (map[string]interface{}, error)
- func RandBytes(size int, exclude ...[]byte) []byte
- func StringifyJSON(data interface{}, ind ...int) ([]byte, error)
- func ToByteArray(res interface{}) []byte
- func ToFloat(res interface{}) float64
- func ToInt(res interface{}) int
- func ToString(res interface{}) string
- func TrimRepeats(b []byte, chars []byte) []byte
- func WatchDir(root string, cb *Watcher)
- type Hashable
- type Watcher
Constants ¶
This section is empty.
Variables ¶
var VarType map[string]reflect.Type
Functions ¶
func CleanArray ¶
func CleanArray(data []interface{}) []interface{}
CleanArray runs `CleanStr` on an []interface{}
CleanStr sanitizes a string to valid UTF-8
func CleanJSON ¶
func CleanJSON(val interface{}) interface{}
CleanJSON runs `CleanStr` on a complex json object recursively
CleanStr sanitizes a string to valid UTF-8
func CleanMap ¶
CleanMap runs `CleanStr` on a map[string]interface{}
CleanStr sanitizes a string to valid UTF-8
func CloseWatchers ¶ added in v3.1.3
func CloseWatchers(root string)
CloseWatchers will close all the watchers with the given root if they were created by goutil
@root pass a file path for a specific watcher or "*" for all watchers that exist
note: this method may include other modules that are using goutil as a dependency
func CompareHash ¶
CompareHash compares a key based hash created by the `NewHash` func to another text, to safely check for equality
uses HMAC with SHA256
the key is also hashed with SHA256
@compare should be a valid hash
func ContainsMap ¶
ContainsMap returns true if a map contains a value
func ContainsMapKey ¶
ContainsMapKey returns true if a map contains a key
func DecodeJSON ¶
DecodeJSON is useful for decoding a JSON output from the body of an http request
example: goutil.DecodeJSON(r.Body)
func Decompress ¶
Decompress is Gzip decompression for a string
func DecryptLocal ¶
DecryptLocal is a Non Standard AES-CFB Decryption method
Notice This Feature Is Experimental ¶
purposely incompatible with other libraries and programing languages
this was made by accident, and this bug is now a feature
func DeepCopyJson ¶
DeepCopyJson will stringify and parse json to create a deep copy and escape pointers
func EncryptLocal ¶
EncryptLocal is a Non Standard AES-CFB Encryption method
Notice This Feature Is Experimental ¶
purposely incompatible with other libraries and programing languages
this was made by accident, and this bug is now a feature
func EscapeHTML ¶
EscapeHTML replaces HTML characters with html entities
Also prevents and removes & from results
func EscapeHTMLArgs ¶
EscapeHTMLArgs escapes quotes and backslashes for use within HTML quotes @quote can be used to only escape specific quotes or chars
func FormatMemoryUsage ¶
FormatMemoryUsage converts bytes to megabytes
func GetFileFromParent ¶
GetFileFromParent checks if the parent (or sub parent) directory of a file contains a specific file or folder
@root is the highest grandparent to check before quitting
@start is the lowest level to start searching from (if a directory is passed, it will not be included in your search)
@search is what file you want to search fro
func GetLinuxInstaller ¶
GetLinuxInstaller attempt to find out what package manager a linux distro is using or has available
func HasLinuxPkg ¶
HasLinuxPkg attempt to check if a linux package is installed
func IndexOf ¶
IndexOf returns the index of a value in an array
returns -1 and an error if the value is not found
func IndexOfMap ¶
IndexOfMap returns the index of a value in a map
returns an error if the value is not found
func InstallLinuxPkg ¶
InstallLinuxPkg attempts to install a linux package
this method will also resolve the sudo command and ask for a user password if needed
this method will not attempt to run an install, if it finds the package is already installed
func IsZeroOfUnderlyingType ¶
func IsZeroOfUnderlyingType(x interface{}) bool
IsZeroOfUnderlyingType can be used to determine if an interface{} in null or empty
func MapArgs ¶ added in v3.0.5
MapArgs will convert a bash argument array ([]string) into a map (map[string]string)
When @args is left blank with no values, it will default to os.Args[1:]
-- Arg Convertions:
"--Key=value" will convert to "key:value"
"--boolKey" will convert to "boolKey:true"
"-flags" will convert to "f:true, l:true, a:true, g:true, s:true" (only if its alphanumeric [A-Za-z0-9]) if -flags is not alphanumeric (example: "-test.paniconexit0" "-test.timeout=10m0s") it will be treated as a --flag (--key=value --boolKey)
keys that match a number ("--1" or "-1") will start with a "-" ("--1=value" -> "-1:value", "-1" -> -1:true) this prevents a number key from conflicting with an index key
everything else is given a number value index starting with 0
this method will not allow --args to have their values modified after they have already been set
func MapArgsByte ¶ added in v3.0.6
MapArgs is just like MapArgs, but it excepts and outputs using []byte instead of string
func RandBytes ¶ added in v3.1.0
RandBytes generates random bytes using crypto/rand
@exclude[0] allows you can to pass an optional []byte to ensure that set of chars will not be included in the output string
@exclude[1] provides a replacement string to put in place of the unwanted chars
@exclude[2:] is currently ignored
func StringifyJSON ¶
StringifyJSON converts a map or array to a JSON string
func ToByteArray ¶
func ToByteArray(res interface{}) []byte
ToByteArray converts multiple types to a []byte
accepts: string, []byte, byte, int32, int, int64, float64, float32
func ToFloat ¶ added in v3.1.5
func ToFloat(res interface{}) float64
ToFloat converts multiple types to a float64
accepts: int, int32, int64, float64, float32, string, []byte, byte
func ToInt ¶
func ToInt(res interface{}) int
ToInt converts multiple types to an int
accepts: int, int32, int64, float64, float32, string, []byte, byte
func ToString ¶
func ToString(res interface{}) string
ToString converts multiple types to a string
accepts: string, []byte, byte, int32, int, int64, float64, float32
func TrimRepeats ¶
TrimRepeats trims repeating adjacent characters and reduces them to one character
@b: byte array to trim
@chars: list of bytes to trim repeats of