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 CompareAsFloat64(a, b any) bool
- func CompareAsMarshaledJson(a, b any) bool
- func ContainsBinaryData(data []byte) bool
- func ContainsStr(strs []string, test string) bool
- func ConvertInt(val any) int64
- func ConvertMap(val any) map[string]any
- func ConvertToWallClockPT(t time.Time) time.Time
- func ConvertUUIDv4Tov7(uuidv4 string) (string, error)
- func CopyToChannel(outputCh chan<- []byte, reader io.Reader) error
- func CopyWithEndBytes(outputBuf *bytes.Buffer, reader io.Reader, endBytes []byte) (bool, error)
- func DecodeDataURL(dataURL string) (mimeType string, data []byte, err error)
- func DecodeStringArray(barr []byte) ([]string, error)
- func DecodeStringMap(barr []byte) (map[string]string, error)
- func DoMapStructure(out any, input any) error
- func DrainChannelSafe[T any](ch <-chan T, debugName string)
- func DumpGoRoutineStacks(w io.Writer)
- 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 FilterValidArch(arch string) (string, error)
- func FindStringInSlice(slice []string, val string) int
- func FormatLsTime(t time.Time) string
- func FormatRelativeTime(modTime time.Time) string
- 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 GetLineColFromOffset(barr []byte, offset int) (int, int)
- 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 GracefulClose(closer io.Closer, debugName, closerName string) bool
- func HasBinaryData(data []byte) bool
- func IndentString(indent string, str string) string
- func IsBinaryContent(data []byte) bool
- func IsNumericType(val any) bool
- func IsPrefix(strs []string, test string) bool
- func JsonMapToStruct(m map[string]any, v interface{}) error
- func JsonValEqual(a, b any) bool
- func LongestPrefix(root string, strs []string) string
- func MapToStruct(in map[string]any, out any) error
- func MarshalIndentNoHTMLString(v any, prefix, indent string) (string, error)
- func MarshalJSONString(s 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 MustPrettyPrintJSON(v any) string
- func NullDecodeStr(barr []byte) (string, error)
- func NullEncodeStr(s string) []byte
- func ParsePartialJson(data []byte) (any, error)
- func Ptr[T any](x T) *T
- func QuickHashString(s string) string
- 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 ReadLineWithTimeout(ch chan LineOutput, timeout time.Duration) (string, error)
- func RemoveElemFromSlice[T comparable](arr []T, elem T) []T
- func SafeDeref[T any](x *T) T
- func SendWithCtxCheck[T any](ctx context.Context, ch chan<- T, val T) bool
- 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 StrSetIntersection(s1 []string, s2 []string) []string
- func StreamToLines(input io.Reader, lineFn func([]byte), readCallback func()) error
- func StreamToLinesChan(input io.Reader) chan LineOutput
- func StrsEqual(s1arr []string, s2arr []string) bool
- func StructToJsonMap(v interface{}) (map[string]any, error)
- func StructToMap(in any) (map[string]any, error)
- func TimeoutFromContext(ctx context.Context, defaultTimeout time.Duration) time.Duration
- func ToFloat64(val any) (float64, bool)
- func ToInt(val any) (int, bool)
- func ToInt64(val any) (int64, bool)
- func ToStr(val any) (string, bool)
- func TruncateString(s string, maxLen int) string
- func WriteFileIfDifferent(fileName string, contents []byte) (bool, error)
- func WriteTemplateToFile(fileName string, templateText string, vars map[string]string) error
- type LineOutput
- type LineWriter
- 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 PTLoc *time.Location
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 CompareAsFloat64 ¶
Helper to handle numeric comparisons as float64
func CompareAsMarshaledJson ¶
func ContainsBinaryData ¶
ContainsBinaryData checks if the provided data contains binary (non-text) content
func ContainsStr ¶
func ConvertInt ¶
converts an int, int64, or float64 to an int64 nil or bad type returns 0
func ConvertMap ¶
func ConvertUUIDv4Tov7 ¶
func CopyToChannel ¶
does *not* close outputCh on EOF or error
func CopyWithEndBytes ¶
returns (isEOF, error)
func DecodeDataURL ¶
DecodeDataURL decodes a data URL and returns the mimetype and raw data bytes
func DecodeStringArray ¶
func DoMapStructure ¶
does a mapstructure using "json" tags
func DrainChannelSafe ¶
DrainChannelSafe will drain a channel until it is empty or until a timeout is reached.
func DumpGoRoutineStacks ¶
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 FilterValidArch ¶
*
- Utility function to convert know architecture patterns
- to the patterns we use. It returns an error if the
- provided name is unknown
func FindStringInSlice ¶
func FormatLsTime ¶
func FormatRelativeTime ¶
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 HasBinaryData ¶
func IndentString ¶
func IsBinaryContent ¶
func JsonMapToStruct ¶
func JsonValEqual ¶
this is a shallow equal, but with special handling for numeric types it will up convert to float64 and compare
func LongestPrefix ¶
func MarshalIndentNoHTMLString ¶
MarshalIndentNoHTMLString marshals the value to JSON with indentation and SetEscapeHTML(false), returning a string
func MarshalJSONString ¶
MarshalJSONString marshals a string to JSON format, returning the properly escaped JSON string. Returns empty string if there's an error (rare).
func MoveSliceIdxToFront ¶
func MustPrettyPrintJSON ¶
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 ParsePartialJson ¶
func Ptr ¶
func Ptr[T any](x T) *T
*
- Utility function for referencing a type with a pointer.
- This is the same as dereferencing with &, but unlike &
- you can directly use it on the ouput of a function
- without needing to create an intermediate variable
func QuickHashString ¶
func QuickParseJson ¶
func RandomHexString ¶
every byte is 4-bits of randomness
func ReUnmarshal ¶
func ReadLineWithTimeout ¶
func ReadLineWithTimeout(ch chan LineOutput, timeout time.Duration) (string, error)
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 SafeDeref ¶
func SafeDeref[T any](x *T) T
*
- Helper function that will deref a pointer if not null
- but returns a default value if it is null.
func ShellHexEscape ¶
returns hex escaped string (\xNN for each byte)
func ShellQuote ¶
minimum maxlen=6, pass -1 for no max length
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 StrSetIntersection ¶
func StreamToLines ¶
func StreamToLinesChan ¶
func StreamToLinesChan(input io.Reader) chan LineOutput
starts a goroutine to drive the channel line output does not include the trailing newline
func StructToJsonMap ¶
func TimeoutFromContext ¶
func TruncateString ¶
func WriteFileIfDifferent ¶
Types ¶
type LineOutput ¶
type LineWriter ¶
type LineWriter struct {
// contains filtered or unexported fields
}
LineWriter is an io.Writer that processes data line-by-line via a callback. Lines do not include the trailing newline. Lines longer than maxLineLength are dropped.
func NewLineWriter ¶
func NewLineWriter(lineFn func([]byte)) *LineWriter
NewLineWriter creates a new LineWriter with the given callback function.
func (*LineWriter) Flush ¶
func (lw *LineWriter) Flush()
Flush outputs any remaining buffered data as a final line. Should be called when the input stream is complete (e.g., at EOF).
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