Documentation
¶
Index ¶
- func BinarySearchBytes(arr [][]byte, target []byte, left int, right int) (int, bool)
- func BytesToStringZeroAlloc(b []byte) string
- func CalculateHashBin(key string) []byte
- func CalculateHashHexBase16String(key string) string
- func CalculateHashSHA1(key string) string
- func CheckExecutable(s string, logger *slog.Logger) (bool, error)
- func CheckFile(s string) bool
- func ContainsMultiple(s string, input []string) bool
- func ConvertLineToCRLF(s string) string
- func DiskSpace() (uint64, error)
- func DuplicateElements[T cmp.Ordered](ts []T) []T
- func FilepathParts(in string) (out []string)
- func GenerateDSVFile(length int) string
- func GenerateDSVLine(length int) string
- func GenerateEmail(lower bool) string
- func GenerateRandomString(length int, lower bool) string
- func GetCurrentFuncName(parent ...bool) string
- func GetFQDN() (string, error)
- func GzipAll(logger *log.Logger, directory string)
- func GzipFile(logger *log.Logger, in string)
- func HasSuffixMultiple(s string, input []string) bool
- func IfAllEmpty[T comparable](v ...T) bool
- func IfAnyEmpty[T comparable](v ...T) bool
- func InitializeLogger(level string, logType string, logFile string, localtime bool, caller int, ...) *phuslu.Logger
- func InitializeSlogLogger(level string, logfile string, format string) *slog.Logger
- func IsLower(s string) bool
- func IsUpper(s string) bool
- func ItoB(i int64) bool
- func LineCounter(logger *log.Logger, r io.Reader, tFlag ...bool) (int, error)
- func PrependInsertReversed[T cmp.Ordered](ts []T, t ...T) []T
- func PrependInsertSliced[T cmp.Ordered](ts []T, t ...T) []T
- func ShuffleSlice[T any](s []T)
- func SortedInsert[T cmp.Ordered](ts []T, t T, logger *slog.Logger) []T
- func SortedInsertByte(ts [][]byte, t []byte) [][]byte
- func SplitMailString(s string) (string, string)
- func StringToBytesZeroAlloc(s string) []byte
- func SymlinkFiles(logger *log.Logger, origin string, target string) error
- func TrackExecutionTime(logger *log.Logger, pre time.Time, msg ...string)
- func TrackTimeSeconds(pre time.Time, fn func(float64))
- func TrimSubstr(s string, substr string) string
- type LDIFRegexps
- type SyslogConn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinarySearchBytes ¶
func BytesToStringZeroAlloc ¶
BytesToStringZeroAlloc converts bytes to a string without memory allocation. NOTE: The given bytes MUST NOT be modified since they share the same backing array with the returned string.
func CalculateHashBin ¶
CalculateHashBin returns the sha1 binary value for a given string `key`.
func CalculateHashHexBase16String ¶
CalculateHashHexBase16String returns the string representation of the sha1 value for a given string (hex, base16).
func CalculateHashSHA1 ¶
CalculateHashSHA1 returns the string representation of the sha1 value for a given string (hex, base16).
func CheckExecutable ¶
CheckExecutable checks if the given executable `s` exists on the PATH. It returns true and nil, else it returns false and an error.
func ContainsMultiple ¶
ContainsMultiple checks if the string `s` contains any of the substrings in the string slice `input`. The function returns true for the first match which returned true, else it returns false.
func ConvertLineToCRLF ¶
ConvertLineToCRLF converts a line ending of \n or \r to \r\n (CR LF)
func DuplicateElements ¶
func FilepathParts ¶
func GenerateDSVLine ¶
Generate DSV line generates a string with n fields, leading with a random email address
func GenerateEmail ¶
GenerateEmail generates a random email address-like string
func GenerateRandomString ¶
func GetCurrentFuncName ¶
GetCurrentFuncName returns a string holding the current function name. Pass any boolean value to it to get the name of the function which called the function.
func GetFQDN ¶
GetFQDN uses the `hostname` binary to look up the fully qualified domain name. It expects to find aaa.bbb.tld or something longer than 1 element if split by dots in the name. The expected length will be bypassed for mocking.
func HasSuffixMultiple ¶
HasSuffixMultiple checks if the string `s` has any of the suffixes in the string slice `input`. The function returns true for the first match which returned true, else it returns false.
func IfAllEmpty ¶
func IfAllEmpty[T comparable](v ...T) bool
func IfAnyEmpty ¶
func IfAnyEmpty[T comparable](v ...T) bool
func InitializeLogger ¶
func InitializeLogger(level string, logType string, logFile string, localtime bool, caller int, sysConn SyslogConn, writer ...*phuslu.Writer) *phuslu.Logger
InitializeLogger initializes a new logger. level: loglevel (trace, debug, info, warn, error, fatal, panic) logType: simple, consolewriter (same as text), consolewritermulti, file, systemd (only available on linux) logFile: file to log to if logType is file, stdout or stderr for simple (defaults to stderr if empty) localtime: boolean, use local time in logs caller: add `file:line` to log output
func InitializeSlogLogger ¶
InitializeSlogLogger initializes a new `log/slog` logger. level: loglevel (debug, info, warning, error) logfile: either stdout, stderr or file format: json or text, every other argument defaults to text
func LineCounter ¶
LineCounter counts the number of lines in a file in a sufficiently fast way.
func PrependInsertReversed ¶
func PrependInsertSliced ¶
func ShuffleSlice ¶
func ShuffleSlice[T any](s []T)
ShuffleSlice randomizes the order of slice `s` via rand.Shuffle.
func SortedInsert ¶
SortedInsert inserts t into ts, where t and ts are of cmp.Ordered type
func SortedInsertByte ¶
SortedInsertByte inserts t (byte slice) into ts (slice of byte slices).
func SplitMailString ¶
func StringToBytesZeroAlloc ¶
StringToBytesZeroAlloc converts a string to a byte slice without memory allocation. NOTE: The returned byte slice MUST NOT be modified since it shares the same backing array with the given string.
func TrackExecutionTime ¶
TrackExecutionTime takes a time.Time value and an optional message, and returns a log message (or fmt.Fprintf if logger was nil) with details on the time spent executing a function.
func TrackTimeSeconds ¶
func TrimSubstr ¶
Types ¶
type LDIFRegexps ¶
func NewLDIFRegexps ¶
func NewLDIFRegexps() LDIFRegexps
func (LDIFRegexps) DissolveDoubleColon ¶
func (l LDIFRegexps) DissolveDoubleColon(s string, t ...bool) string
DissolveDoubleColon replaces all `t::` with `t:` in `s`. This is a work-around for https://github.com/go-ldap/ldif/issues/23.
func (LDIFRegexps) DissolveEmptyValues ¶
func (l LDIFRegexps) DissolveEmptyValues(s string, t ...bool) string
DissolveEmptyValues removes all empty value lines in `s`. This is a work-around for https://github.com/go-ldap/ldif/issues/21.