stdlib

package
v0.0.0-...-1329d2c Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorNum      = "<BAD-TYPE>"    // Error parsing the principle value of the input because of unexpected type (numeric)
	ErrorParsing  = "<PARSE-ERROR>" // Error parsing the principle value of the input (non-numeric)
	ErrorArgCount = "<ARGN>"        // Function to not support a variation with the given argument count
	ErrorConst    = "<CONST>"       // Expected constant value
	ErrorEnum     = "<ENUM>"        // A given value is not contained within a set
	ErrorArgName  = "<NAME>"        // A variable accessed by a given name does not exist
	ErrorEmpty    = "<EMPTY>"       // A value was expected, but was empty
	ErrorFile     = "<FILE>"        // Unable to read file
	ErrorValue    = "<VALUE>"       // Value is out of range or invalid (eg. range incrementer is 0)
)

Realtime errors

Variables

View Source
var (
	ErrNum     = newFuncErr(ErrorNum, "invalid arg type, expected int") // always numeric
	ErrParsing = newFuncErr(ErrorParsing, "unable to parse")            // always non-numeric (eg expression or time)
	ErrConst   = newFuncErr(ErrorConst, "expected const")
	ErrEnum    = newFuncErr(ErrorEnum, "value not in set")
	ErrEmpty   = newFuncErr(ErrorEmpty, "invalid empty value")
	ErrFile    = newFuncErr(ErrorFile, "unable to read file")
	ErrValue   = newFuncErr(ErrorValue, "value out of range")
)

Compilation errors

View Source
var DisableLoad = false
View Source
var (
	ErrArgCount = errors.New("invalid number of arguments")
)
View Source
var StandardFunctions = map[string]KeyBuilderFunction{
	"coalesce":    KeyBuilderFunction(kfCoalesce),
	"bucket":      KeyBuilderFunction(kfBucket),
	"bucketrange": kfBucketRange,
	"clamp":       KeyBuilderFunction(kfClamp),
	"expbucket":   KeyBuilderFunction(kfExpBucket),

	"isint": KeyBuilderFunction(kfIsInt),
	"isnum": KeyBuilderFunction(kfIsNum),

	"sumi":  arithmaticHelperi(func(a, b int) int { return a + b }),
	"subi":  arithmaticHelperi(func(a, b int) int { return a - b }),
	"multi": arithmaticHelperi(func(a, b int) int { return a * b }),
	"divi": arithmaticHelperi(func(a, b int) int {
		if b == 0 {
			return math.MaxInt
		}
		return a / b
	}),
	"modi": arithmaticHelperi(func(a, b int) int {
		if b == 0 {
			return 0
		}
		return a % b
	}),
	"maxi": arithmaticHelperi(func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}),
	"mini": arithmaticHelperi(func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}),
	"sumf":  arithmaticHelperf(func(a, b float64) float64 { return a + b }),
	"subf":  arithmaticHelperf(func(a, b float64) float64 { return a - b }),
	"multf": arithmaticHelperf(func(a, b float64) float64 { return a * b }),
	"divf":  arithmaticHelperf(func(a, b float64) float64 { return a / b }),
	"ceil":  unaryArithmaticHelperfi(func(f float64) int64 { return int64(math.Ceil(f)) }),
	"floor": unaryArithmaticHelperfi(func(f float64) int64 { return int64(math.Floor(f)) }),
	"log10": unaryArithmaticHelperf(math.Log10),
	"log2":  unaryArithmaticHelperf(math.Log2),
	"ln":    unaryArithmaticHelperf(math.Log),
	"pow":   arithmaticHelperf(math.Pow),
	"sqrt":  unaryArithmaticHelperf(math.Sqrt),
	"round": kfRound,

	"!": kfMath,

	"if":     KeyBuilderFunction(kfIf),
	"switch": kfSwitch,
	"unless": KeyBuilderFunction(kfUnless),
	"eq": stringComparator(func(a, b string) string {
		if a == b {
			return TruthyVal
		}
		return FalsyVal
	}),
	"neq": stringComparator(func(a, b string) string {
		if a != b {
			return TruthyVal
		}
		return FalsyVal
	}),
	"not": KeyBuilderFunction(kfNot),
	"lt":  arithmaticEqualityHelper(func(a, b float64) bool { return a < b }),
	"gt":  arithmaticEqualityHelper(func(a, b float64) bool { return a > b }),
	"lte": arithmaticEqualityHelper(func(a, b float64) bool { return a <= b }),
	"gte": arithmaticEqualityHelper(func(a, b float64) bool { return a >= b }),
	"and": KeyBuilderFunction(kfAnd),
	"or":  KeyBuilderFunction(kfOr),

	"len":       KeyBuilderFunction(kfLen),
	"like":      KeyBuilderFunction(kfLike),
	"prefix":    KeyBuilderFunction(kfPrefix),
	"suffix":    KeyBuilderFunction(kfSuffix),
	"format":    KeyBuilderFunction(kfFormat),
	"substr":    KeyBuilderFunction(kfSubstr),
	"select":    KeyBuilderFunction(kfSelect),
	"index":     kfIndexOf,
	"lastindex": kfLastIndexOf,
	"pick":      kfPick,
	"upper":     KeyBuilderFunction(kfUpper),
	"lower":     KeyBuilderFunction(kfLower),
	"replace":   KeyBuilderFunction(kfReplace),

	"tab": kfJoin('\t'),
	"$":   kfJoin(ArraySeparator),

	"@":       kfJoin(ArraySeparator),
	"@len":    kfArrayLen,
	"@map":    kfArrayMap,
	"@split":  kfArraySplit,
	"@select": kfArraySelect,
	"@join":   kfArrayJoin,
	"@reduce": kfArrayReduce,
	"@filter": kfArrayFilter,
	"@slice":  kfArraySlice,
	"@in":     kfArrayIn,
	"@range":  kfArrayRange,
	"@for":    kfArrayFor,

	"basename": kfPathBase,
	"dirname":  kfPathDir,
	"extname":  kfPathExt,

	"load":   kfLoadFile,
	"lookup": kfLookupKey,
	"haskey": kfHasKey,

	"hi":         KeyBuilderFunction(kfHumanizeInt),
	"hf":         KeyBuilderFunction(kfHumanizeFloat),
	"bytesize":   kfBytesize,
	"bytesizesi": kfBytesizeSi,
	"downscale":  kfDownscale,
	"percent":    kfPercent,

	"json": KeyBuilderFunction(kfJsonQuery),

	"csv": KeyBuilderFunction(kfCsv),

	"time":           KeyBuilderFunction(kfTimeParse),
	"timeformat":     KeyBuilderFunction(kfTimeFormat),
	"timeattr":       KeyBuilderFunction(kfTimeAttr),
	"buckettime":     KeyBuilderFunction(kfBucketTime),
	"duration":       KeyBuilderFunction(kfDuration),
	"durationformat": KeyBuilderFunction(kfDurationFormat),

	"color":  KeyBuilderFunction(kfColor),
	"repeat": KeyBuilderFunction(kfRepeat),
	"bar":    KeyBuilderFunction(kfBar),
}

Functions

func EvalArgInt

func EvalArgInt(stages []expressions.KeyBuilderStage, idx int, dflt int) (int, bool)

Helper to EvalStageInt

func EvalStageIndexOrDefault

func EvalStageIndexOrDefault(stages []expressions.KeyBuilderStage, idx int, dflt string) string

Eval a stage, but upon any error, returns default instead Deprecated: Consider using EvalStaticStage for better error detection

func EvalStageInt

func EvalStageInt(stage expressions.KeyBuilderStage) (int, bool)

Evals stage and parses as int. If fails for any reason (stage eval or parsing), will return false

func EvalStageInt64

func EvalStageInt64(stage expressions.KeyBuilderStage) (int64, bool)

Evals stage and parses as int. If fails for any reason (stage eval or parsing), will return false

func NewStdKeyBuilder

func NewStdKeyBuilder() *expressions.KeyBuilder

func NewStdKeyBuilderEx

func NewStdKeyBuilderEx(autoOptimize bool) *expressions.KeyBuilder

Types

This section is empty.

Jump to

Keyboard shortcuts

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