pkg

package
v0.0.0-...-5ccf439 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2025 License: 0BSD Imports: 27 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinarySearchBytes

func BinarySearchBytes(arr [][]byte, target []byte, left int, right int) (int, bool)

func BytesToStringZeroAlloc

func BytesToStringZeroAlloc(b []byte) string

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

func CalculateHashBin(key string) []byte

CalculateHashBin returns the sha1 binary value for a given string `key`.

func CalculateHashHexBase16String

func CalculateHashHexBase16String(key string) string

CalculateHashHexBase16String returns the string representation of the sha1 value for a given string (hex, base16).

func CalculateHashSHA1

func CalculateHashSHA1(key string) string

CalculateHashSHA1 returns the string representation of the sha1 value for a given string (hex, base16).

func CheckExecutable

func CheckExecutable(s string, logger *slog.Logger) (bool, error)

CheckExecutable checks if the given executable `s` exists on the PATH. It returns true and nil, else it returns false and an error.

func CheckFile

func CheckFile(s string) bool

CheckFile checks if the given file `s` exists.

func ContainsMultiple

func ContainsMultiple(s string, input []string) bool

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

func ConvertLineToCRLF(s string) string

ConvertLineToCRLF converts a line ending of \n or \r to \r\n (CR LF)

func DiskSpace

func DiskSpace() (uint64, error)

DiskSpace returns the available space in bytes or 0 in case of error.

func DuplicateElements

func DuplicateElements[T cmp.Ordered](ts []T) []T

func FilepathParts

func FilepathParts(in string) (out []string)

func GenerateDSVFile

func GenerateDSVFile(length int) string

Generate DSV file

func GenerateDSVLine

func GenerateDSVLine(length int) string

Generate DSV line generates a string with n fields, leading with a random email address

func GenerateEmail

func GenerateEmail(lower bool) string

GenerateEmail generates a random email address-like string

func GenerateRandomString

func GenerateRandomString(length int, lower bool) string

func GetCurrentFuncName

func GetCurrentFuncName(parent ...bool) string

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

func GetFQDN() (string, error)

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 GzipAll

func GzipAll(logger *log.Logger, directory string)

GzipAll compresses all the files found in `directory`.

func GzipFile

func GzipFile(logger *log.Logger, in string)

GzipFile compresses the file `in` to `in`.gz

func HasSuffixMultiple

func HasSuffixMultiple(s string, input []string) bool

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

func InitializeSlogLogger(level string, logfile string, format string) *slog.Logger

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 IsLower

func IsLower(s string) bool

func IsUpper

func IsUpper(s string) bool

func ItoB

func ItoB(i int64) bool

func LineCounter

func LineCounter(logger *log.Logger, r io.Reader, tFlag ...bool) (int, error)

LineCounter counts the number of lines in a file in a sufficiently fast way.

func PrependInsertReversed

func PrependInsertReversed[T cmp.Ordered](ts []T, t ...T) []T

func PrependInsertSliced

func PrependInsertSliced[T cmp.Ordered](ts []T, t ...T) []T

func ShuffleSlice

func ShuffleSlice[T any](s []T)

ShuffleSlice randomizes the order of slice `s` via rand.Shuffle.

func SortedInsert

func SortedInsert[T cmp.Ordered](ts []T, t T, logger *slog.Logger) []T

SortedInsert inserts t into ts, where t and ts are of cmp.Ordered type

func SortedInsertByte

func SortedInsertByte(ts [][]byte, t []byte) [][]byte

SortedInsertByte inserts t (byte slice) into ts (slice of byte slices).

func SplitMailString

func SplitMailString(s string) (string, string)

func StringToBytesZeroAlloc

func StringToBytesZeroAlloc(s string) []byte

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 SymlinkFiles

func SymlinkFiles(logger *log.Logger, origin string, target string) error

func TrackExecutionTime

func TrackExecutionTime(logger *log.Logger, pre time.Time, msg ...string)

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 TrackTimeSeconds(pre time.Time, fn func(float64))

func TrimSubstr

func TrimSubstr(s string, substr string) string

Types

type LDIFRegexps

type LDIFRegexps struct {
	EmptyValue  *regexp.Regexp
	DoubleColon *regexp.Regexp
}

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.

type SyslogConn

type SyslogConn struct {
	Protocol string
	Port     string
	Address  string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL