Documentation ¶
Index ¶
- Constants
- Variables
- func AddElemToSliceUniq[T comparable](arr []T, elem T) []T
- func AddInt(left, right int) (int, error)
- func AddIntSlice(vals ...int) (int, error)
- func AppendNonZeroRandomBytes(b []byte, randLen int) []byte
- func AtoiNoErr(str string) int
- func AtomicRenameCopy(dstPath string, srcPath string, perms os.FileMode) error
- func ByteMapsEqual(m1 map[string][]byte, m2 map[string][]byte) bool
- func ChunkSlice[T any](s []T, chunkSize int) [][]T
- func CombineMaps[V any](m1 map[string]V, m2 map[string]V)
- func CombineStrArrays(sarr1 []string, sarr2 []string) []string
- func ContainsStr(strs []string, test string) bool
- func CopyToChannel(outputCh chan<- []byte, reader io.Reader) error
- func CopyWithEndBytes(outputBuf *bytes.Buffer, reader io.Reader, endBytes []byte) (bool, error)
- func DecodeStringArray(barr []byte) ([]string, error)
- func DecodeStringMap(barr []byte) (map[string]string, error)
- func DetectMimeType(path string, fileInfo fs.FileInfo, extended bool) string
- func DoMapStructure(out any, input any) error
- func EllipsisStr(s string, maxLen int) string
- func EncodeStringArray(arr []string) []byte
- func EncodeStringMap(m map[string]string) []byte
- func EncodedStringArrayGetFirstVal(encoded []byte) string
- func EncodedStringArrayHasFirstVal(encoded []byte, firstKey string) bool
- func GetBool(v interface{}, field string) bool
- func GetCmdExitCode(cmd *exec.Cmd, err error) int
- func GetExitCode(err error) int
- func GetFirstLine(s string) string
- func GetJsonTag(field reflect.StructField) string
- func GetMapKeys[K comparable, V any](m map[K]V) []K
- func GetOrderedMapKeys[V any](m map[string]V) []string
- func GetOrderedStringerMapKeys[K interface{ ... }, V any](m map[K]V) []K
- func GetStrArr(v interface{}, field string) []string
- func IndentString(indent string, str string) string
- func IsPrefix(strs []string, test string) bool
- func JsonMapToStruct(m map[string]any, v interface{}) error
- func LongestPrefix(root string, strs []string) string
- func MergeStrMaps[T any](m1 map[string]T, m2 map[string]T) map[string]T
- func MoveSliceIdxToFront[T any](arr []T, idx int) []T
- func NullDecodeStr(barr []byte) (string, error)
- func NullEncodeStr(s string) []byte
- func QuickJson(v interface{}) string
- func QuickParseJson[T any](s string) T
- func RandomHexString(numHexDigits int) (string, error)
- func ReUnmarshal(out any, in any) error
- func RemoveElemFromSlice[T comparable](arr []T, elem T) []T
- func Sha1Hash(data []byte) string
- func ShellHexEscape(s string) string
- func ShellQuote(val string, forceQuote bool, maxLen int) string
- func SliceIdx[T comparable](arr []T, elem T) int
- func SortStringRunes(s string) string
- func StarMatchString(pattern string, s string, delimiter string) bool
- func StrArrayToMap(sarr []string) map[string]bool
- func StrMapsEqual(m1 map[string]string, m2 map[string]string) bool
- func StrsEqual(s1arr []string, s2arr []string) bool
- func StructToJsonMap(v interface{}) (map[string]any, error)
- func WriteFileIfDifferent(fileName string, contents []byte) (bool, error)
- func WriteTemplateToFile(fileName string, templateText string, vars map[string]string) error
- type StrWithPos
Constants ¶
const NoStrPos = -1
sentinel value for StrWithPos.Pos to indicate no position
Variables ¶
var ErrOverflow = errors.New("integer overflow")
var HexDigits = []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}
var StaticMimeTypeMap = map[string]string{}/* 1254 elements not displayed */
Functions ¶
func AddElemToSliceUniq ¶
func AddElemToSliceUniq[T comparable](arr []T, elem T) []T
func AddIntSlice ¶
Add a slice of ints, returning an error if the result overflows.
func AtomicRenameCopy ¶
func ChunkSlice ¶
func CombineMaps ¶
will overwrite m1 with m2's values
func CombineStrArrays ¶
combines string arrays and removes duplicates (returns a new array)
func ContainsStr ¶
func CopyToChannel ¶
does *not* close outputCh on EOF or error
func CopyWithEndBytes ¶
returns (isEOF, error)
func DecodeStringArray ¶
func DetectMimeType ¶
on error just returns "" does not return "application/octet-stream" as this is considered a detection failure can pass an existing fileInfo to avoid re-statting the file
func DoMapStructure ¶
does a mapstructure using "json" tags
func EllipsisStr ¶
func EncodeStringArray ¶
func EncodeStringMap ¶
func EncodedStringArrayGetFirstVal ¶
on encoding error returns "" this is used to perform logic on first value without decoding the entire array
func GetExitCode ¶
func GetFirstLine ¶
func GetJsonTag ¶
func GetJsonTag(field reflect.StructField) string
func GetMapKeys ¶
func GetMapKeys[K comparable, V any](m map[K]V) []K
func GetOrderedMapKeys ¶
func GetOrderedStringerMapKeys ¶
func GetOrderedStringerMapKeys[K interface { comparable fmt.Stringer }, V any](m map[K]V) []K
func IndentString ¶
func JsonMapToStruct ¶
func LongestPrefix ¶
func MoveSliceIdxToFront ¶
func NullDecodeStr ¶
func NullEncodeStr ¶
encodes a string, removing null/zero bytes (and separators '|') a zero byte is encoded as "\0", a '\' is encoded as "\\", sep is encoded as "\s" allows for easy double splitting (first on \x00, and next on "|")
func QuickParseJson ¶
func RandomHexString ¶
every byte is 4-bits of randomness
func ReUnmarshal ¶
func RemoveElemFromSlice ¶
func RemoveElemFromSlice[T comparable](arr []T, elem T) []T
removes an element from a slice and modifies the original slice (the backing elements) if it removes the last element from the slice, it will return nil so we free the original slice's backing memory
func ShellHexEscape ¶
returns hex escaped string (\xNN for each byte)
func SliceIdx ¶
func SliceIdx[T comparable](arr []T, elem T) int
func SortStringRunes ¶
func StarMatchString ¶
matches a delimited string with a pattern string the pattern string can contain "*" to match a single part, or "**" to match the rest of the string note that "**" may only appear at the end of the string
func StrArrayToMap ¶
func StructToJsonMap ¶
func WriteFileIfDifferent ¶ added in v0.8.7
Types ¶
type StrWithPos ¶
type StrWithPos struct { Str string `json:"str"` Pos int `json:"pos"` // this is a 'rune' position (not a byte position) }
func ParseToSP ¶
func ParseToSP(s string) StrWithPos
func (StrWithPos) Append ¶
func (sp StrWithPos) Append(str string) StrWithPos
func (StrWithPos) Prepend ¶
func (sp StrWithPos) Prepend(str string) StrWithPos
func (StrWithPos) String ¶
func (sp StrWithPos) String() string