Documentation
¶
Overview ¶
Package stdlib contains standard library functions exposed to River configs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Functions = map[string]interface{}{ "env": os.Getenv, "concat": value.RawFunction(func(funcValue value.Value, args ...value.Value) (value.Value, error) { if len(args) == 0 { return value.Array(), nil } // finalSize is the final size of the resulting concatenated array. We type // check our arguments while computing what finalSize will be. var finalSize int for i, arg := range args { if arg.Type() != value.TypeArray { return value.Null, value.ArgError{ Function: funcValue, Argument: arg, Index: i, Inner: value.TypeError{ Value: arg, Expected: value.TypeArray, }, } } finalSize += arg.Len() } if len(args) == 1 { return args[0], nil } useType := args[0].Reflect().Type() for i := 1; i < len(args); i++ { if args[i].Reflect().Type() != useType { useType = reflect.SliceOf(goAny) break } } raw := reflect.MakeSlice(useType, finalSize, finalSize) var argNum int for _, arg := range args { for i := 0; i < arg.Len(); i++ { elem := arg.Index(i) if elem.Type() != value.TypeNull { raw.Index(argNum).Set(elem.Reflect()) } argNum++ } } return value.Encode(raw.Interface()), nil }), "json_decode": func(in string) (interface{}, error) { var res interface{} err := json.Unmarshal([]byte(in), &res) if err != nil { return nil, err } return res, nil }, }
Functions returns the list of stdlib functions by name. The interface{} value is always a River-compatible function value, where functions have at least one non-error return value, with an optionally supported error return value as the second return value.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.