utils

package
v0.9.19 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DateStrOr

func DateStrOr(input string, defval time.Time) time.Time

parse string, return time.Time or defauls

func DecodePurl

func DecodePurl(input string) string

func DirExists

func DirExists(path string) bool

Return true if path exists and is a direcroty

func DsnHostPortOr

func DsnHostPortOr(input, defval string) string

return host:port from DSN like "docker://user:pwd@pharos.alfa.lan:123/?mi=off"

func DsnParaBoolOr

func DsnParaBoolOr(input, key string, defval bool) bool

func DsnParaOr

func DsnParaOr(input, key, defval string) string

func DsnPasswordOr

func DsnPasswordOr(input, defval string) string

func DsnUserOr

func DsnUserOr(input, defval string) string

func DurationOr

func DurationOr(input string, defval time.Duration) time.Duration

parse string, return time.Duration or default

func ElapsedFunc

func ElapsedFunc() func() time.Duration

func EnvOrDefaultFunc

func EnvOrDefaultFunc(prefix, envfile string) func(string, string) string

return function (closure) thats returns the <prefix>_<name> envvar if it exists, else the default value

func Hostname

func Hostname() string

func HumanDeltaMilisec

func HumanDeltaMilisec(delta time.Duration) string

func HumanDeltaMin

func HumanDeltaMin(delta time.Duration) string

return humanized time delat rounded to minuts (not to have like 1h12m1.112521806s)

func HumanDeltaSec

func HumanDeltaSec(delta time.Duration) string

func IsInstalled

func IsInstalled(cmd string) bool

return true if given program is installed (found in $PATH)

func LeftOfFirstOr

func LeftOfFirstOr(input, key, defval string) string

return left of key of input or default

func MaskDsn

func MaskDsn(input string) string

return DSN with password masked as ***

func NoColorCodes

func NoColorCodes(input string) string

remove ansi color codes from string (from console output)

func OsWhich

func OsWhich(cmd string) (string, error)

func PropOr

func PropOr[T any](xc map[string]any, key string, defval T) T

return value at key or default

func RightOfFirstOr

func RightOfFirstOr(input, key, defval string) string

return right of key of input or default

func RightOfPrefixOr

func RightOfPrefixOr(input, prefix, defval string) string

return right of <prefix> of string or default

func SetPath

func SetPath(m map[string]any, path string, value any)

func ShortDigest

func ShortDigest(input string) string

return left of digest, e.g. "sha256:f85340bf132ae1"

func ToBool

func ToBool(input string) bool

return true if input string is one of 1, t, true, on, yes

func ToNumOr

func ToNumOr[T Numeric](input string, defval T) T

convert to T or default

Types

type Numeric

type Numeric interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64
}

numberic types

type SafeIntMap

type SafeIntMap struct {
	Value map[string]int
	// contains filtered or unexported fields
}

Int Map

func NewSafeIntMap

func NewSafeIntMap() *SafeIntMap

func (*SafeIntMap) Inc

func (rx *SafeIntMap) Inc(key string) int

func (*SafeIntMap) Sum

func (rx *SafeIntMap) Sum() int

func (*SafeIntMap) Val

func (rx *SafeIntMap) Val(key string) int

type SafeTimeMap

type SafeTimeMap struct {
	Value map[string]time.Time
	// contains filtered or unexported fields
}

Time Map

func NewSafeTimeMap

func NewSafeTimeMap() *SafeTimeMap

func (*SafeTimeMap) Set

func (rx *SafeTimeMap) Set(key string, t time.Time)

type ZStd

type ZStd struct {
	// contains filtered or unexported fields
}

func NewZStd

func NewZStd() (*ZStd, error)

experiments showd best compromise with level 3

func (*ZStd) Compress

func (rx *ZStd) Compress(data []byte) []byte

func (*ZStd) Decompress

func (rx *ZStd) Decompress(data []byte) ([]byte, error)

Jump to

Keyboard shortcuts

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