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 } raw := make([]value.Value, 0, finalSize) for _, arg := range args { for i := 0; i < arg.Len(); i++ { raw = append(raw, arg.Index(i)) } } return value.Array(raw...), 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 }, "discovery_target_decode": func(in string) (interface{}, error) { var targetGroups []*targetgroup.Group if err := json.Unmarshal([]byte(in), &targetGroups); err != nil { return nil, err } var res []discovery.Target for _, group := range targetGroups { for _, target := range group.Targets { outputTarget := make(discovery.Target, len(group.Labels)+len(target)) for k, v := range group.Labels { outputTarget[string(k)] = string(v) } for k, v := range target { outputTarget[string(k)] = string(v) } res = append(res, outputTarget) } } 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.