Documentation ¶
Overview ¶
Package builtins contains function definitions and implementation for built-in mapping functions.
Index ¶
- Variables
- func And(args ...jsonutil.JSONToken) (jsonutil.JSONBool, error)
- func CurrentTime(format jsonutil.JSONStr, tz jsonutil.JSONStr) (jsonutil.JSONStr, error)
- func DebugString(t jsonutil.JSONToken) (jsonutil.JSONStr, error)
- func Div(left jsonutil.JSONNum, right jsonutil.JSONNum) (jsonutil.JSONNum, error)
- func Eq(args ...jsonutil.JSONToken) (jsonutil.JSONBool, error)
- func Flatten(array jsonutil.JSONArr) (jsonutil.JSONArr, error)
- func Gt(left jsonutil.JSONNum, right jsonutil.JSONNum) (jsonutil.JSONBool, error)
- func GtEq(left jsonutil.JSONNum, right jsonutil.JSONNum) (jsonutil.JSONBool, error)
- func Hash(obj jsonutil.JSONToken) (jsonutil.JSONStr, error)
- func IntHash(obj jsonutil.JSONToken) (jsonutil.JSONNum, error)
- func IsNil(object jsonutil.JSONToken) (jsonutil.JSONBool, error)
- func IsNotNil(object jsonutil.JSONToken) (jsonutil.JSONBool, error)
- func ListCat(args ...jsonutil.JSONArr) (jsonutil.JSONArr, error)
- func ListLen(in jsonutil.JSONArr) (jsonutil.JSONNum, error)
- func ListOf(args ...jsonutil.JSONToken) (jsonutil.JSONArr, error)
- func Lt(left jsonutil.JSONNum, right jsonutil.JSONNum) (jsonutil.JSONBool, error)
- func LtEq(left jsonutil.JSONNum, right jsonutil.JSONNum) (jsonutil.JSONBool, error)
- func MatchesRegex(str jsonutil.JSONStr, regex jsonutil.JSONStr) (jsonutil.JSONBool, error)
- func MergeJSON(arr jsonutil.JSONArr, overwriteArrays jsonutil.JSONBool) (jsonutil.JSONToken, error)
- func Mod(left jsonutil.JSONNum, right jsonutil.JSONNum) (jsonutil.JSONNum, error)
- func Mul(operands ...jsonutil.JSONNum) (jsonutil.JSONNum, error)
- func MultiFormatParseTime(format jsonutil.JSONArr, date jsonutil.JSONStr) (jsonutil.JSONStr, error)
- func NEq(args ...jsonutil.JSONToken) (jsonutil.JSONBool, error)
- func Not(object jsonutil.JSONToken) (jsonutil.JSONBool, error)
- func Or(args ...jsonutil.JSONToken) (jsonutil.JSONBool, error)
- func ParseFloat(str jsonutil.JSONStr) (jsonutil.JSONNum, error)
- func ParseInt(str jsonutil.JSONStr) (jsonutil.JSONNum, error)
- func ParseTime(format jsonutil.JSONStr, date jsonutil.JSONStr) (jsonutil.JSONStr, error)
- func ParseUnixTime(unit jsonutil.JSONStr, ts jsonutil.JSONNum, format jsonutil.JSONStr, ...) (jsonutil.JSONStr, error)
- func Range(start jsonutil.JSONNum, end jsonutil.JSONNum) (jsonutil.JSONArr, error)
- func ReformatTime(inFormat, date, outFormat jsonutil.JSONStr) (jsonutil.JSONStr, error)
- func SortAndTakeTop(arr jsonutil.JSONArr, key jsonutil.JSONStr, desc jsonutil.JSONBool) (jsonutil.JSONToken, error)
- func SplitTime(format jsonutil.JSONStr, date jsonutil.JSONStr) (jsonutil.JSONArr, error)
- func StrCat(args ...jsonutil.JSONToken) (jsonutil.JSONStr, error)
- func StrFmt(format jsonutil.JSONStr, item jsonutil.JSONToken) (jsonutil.JSONStr, error)
- func StrJoin(sep jsonutil.JSONStr, args ...jsonutil.JSONToken) (jsonutil.JSONStr, error)
- func StrSplit(str jsonutil.JSONStr, sep jsonutil.JSONStr) (jsonutil.JSONArr, error)
- func Sub(left jsonutil.JSONNum, right jsonutil.JSONNum) (jsonutil.JSONNum, error)
- func SubStr(str jsonutil.JSONStr, start, end jsonutil.JSONNum) (jsonutil.JSONStr, error)
- func Sum(operands ...jsonutil.JSONNum) (jsonutil.JSONNum, error)
- func ToLower(str jsonutil.JSONStr) (jsonutil.JSONStr, error)
- func ToUpper(str jsonutil.JSONStr) (jsonutil.JSONStr, error)
- func Trim(str jsonutil.JSONStr) (jsonutil.JSONStr, error)
- func Type(object jsonutil.JSONToken) (jsonutil.JSONStr, error)
- func UUID() (jsonutil.JSONStr, error)
- func UnionBy(items jsonutil.JSONArr, keys ...jsonutil.JSONStr) (jsonutil.JSONArr, error)
- func Unique(array jsonutil.JSONArr) (jsonutil.JSONArr, error)
- func UnnestArrays(c jsonutil.JSONContainer) (jsonutil.JSONArr, error)
- func Void(unused ...jsonutil.JSONToken) (jsonutil.JSONToken, error)
Constants ¶
This section is empty.
Variables ¶
var BuiltinFunctions = map[string]interface{}{ "$Div": Div, "$Mod": Mod, "$Mul": Mul, "$Sub": Sub, "$Sum": Sum, "$Flatten": Flatten, "$ListCat": ListCat, "$ListLen": ListLen, "$ListOf": ListOf, "$SortAndTakeTop": SortAndTakeTop, "$Range": Range, "$UnionBy": UnionBy, "$Unique": Unique, "$UnnestArrays": UnnestArrays, "$CurrentTime": CurrentTime, "$MultiFormatParseTime": MultiFormatParseTime, "$ParseTime": ParseTime, "$ParseUnixTime": ParseUnixTime, "$ReformatTime": ReformatTime, "$SplitTime": SplitTime, "$Hash": Hash, "$IntHash": IntHash, "$IsNil": IsNil, "$IsNotNil": IsNotNil, "$MergeJSON": MergeJSON, "$UUID": UUID, "$Type": Type, "$DebugString": DebugString, "$Void": Void, "$And": And, "$Eq": Eq, "$Gt": Gt, "$GtEq": GtEq, "$Lt": Lt, "$LtEq": LtEq, "$NEq": NEq, "$Not": Not, "$Or": Or, "$MatchesRegex": MatchesRegex, "$ParseFloat": ParseFloat, "$ParseInt": ParseInt, "$SubStr": SubStr, "$StrCat": StrCat, "$StrFmt": StrFmt, "$StrJoin": StrJoin, "$StrSplit": StrSplit, "$ToLower": ToLower, "$ToUpper": ToUpper, "$Trim": Trim, "$base64encode": base64encode, }
When adding a built-in, remember to add it to the map below with its name as the key.
var Now = time.Now
Now is exported to allow for mocking in tests.
Functions ¶
func CurrentTime ¶
CurrentTime returns the current time based on the Go func time.Now (https://golang.org/pkg/time/#Now). The function accepts a time format layout (https://golang.org/pkg/time/#Time.Format) and an IANA formatted time zone string (https://www.iana.org/time-zones). A string representing the current time is returned. A default layout of '2006-01-02 03:04:05'and a default time zone of 'UTC' will be used if not provided.
func DebugString ¶
DebugString converts the JSON element to a string representation by recursively converting objects to strings.
func Flatten ¶
Flatten turns a nested array of arrays (of any depth) into a single array. Item ordering is preserved, depth first.
func Hash ¶
Hash converts the given item into a hash. Key order is not considered (array item order is). This is not cryptographically secure, and is not to be used for secure hashing.
func IntHash ¶
IntHash converts the given item into a integer hash. Key order is not considered (array item order is). This is not cryptographically secure, and is not to be used for secure hashing.
func MatchesRegex ¶
MatchesRegex returns true iff the string matches the regex pattern.
func MergeJSON ¶
MergeJSON merges the elements in the JSONArr into one JSON object by repeatedly calling the merge function. The merge function overwrites single fields and concatenates array fields (unless overwriteArrays is true, in which case arrays are overwritten).
func MultiFormatParseTime ¶
MultiFormatParseTime converts the time in the specified formats to RFC3339 (https://www.ietf.org/rfc/rfc3339.txt) format. It tries the formats in order and returns an error if none of the formats match. The function accepts a go time format layout (https://golang.org/pkg/time/#Time.Format) or Python time format layout (defined in timeTokenMap)
func ParseFloat ¶
ParseFloat parses a string into a float.
func ParseTime ¶
ParseTime converts the time in the specified format to RFC3339 (https://www.ietf.org/rfc/rfc3339.txt) format. The function accepts a go time format layout (https://golang.org/pkg/time/#Time.Format) or Python time format layout (defined in timeTokenMap)
func ParseUnixTime ¶
func ParseUnixTime(unit jsonutil.JSONStr, ts jsonutil.JSONNum, format jsonutil.JSONStr, tz jsonutil.JSONStr) (jsonutil.JSONStr, error)
ParseUnixTime parses a unit and a unix timestamp into the speficied format. The function accepts a go time format layout (https://golang.org/pkg/time/#Time.Format) and Python time format layout (defined in timeTokenMap)
func Range ¶
Range generates an array of sequentially ordered number from start (inclusive) to end (exclusive) by a step of 1. Example: $Range(2, 5) returns: [2, 3, 4] $Range(5, 2) returns: [5, 4, 3] $Range(-2, 1) returns: [-2, -1, 0]
func ReformatTime ¶
ReformatTime uses a Go or Python time-format to convert date into another Go or Python time-formatted date time.
func SortAndTakeTop ¶
func SortAndTakeTop(arr jsonutil.JSONArr, key jsonutil.JSONStr, desc jsonutil.JSONBool) (jsonutil.JSONToken, error)
SortAndTakeTop sorts the elements in the array by the key in the specified direction and returns the top element.
func SplitTime ¶
SplitTime splits a time string into components based on the Go (https://golang.org/pkg/time/#Time.Format) and Python time-format provided. An array with all components (year, month, day, hour, minute, second and nanosecond) will be returned.
func StrFmt ¶
StrFmt formats the given item using the given Go format specifier (https://golang.org/pkg/fmt/).
func StrJoin ¶
StrJoin joins the inputs together and adds the separator between them. Non-string arguments are converted to strings before joining.
func SubStr ¶
SubStr returns a part of the string that is between the start index (inclusive) and the end index (exclusive). If the end index is greater than the length of the string, the end index is truncated to the length.
func ToLower ¶
ToLower converts the given string with all unicode characters mapped to their lowercase.
func ToUpper ¶
ToUpper converts the given string with all unicode characters mapped to their uppercase.
func UUID ¶
UUID generates a RFC4122 (https://tools.ietf.org/html/rfc4122) UUID.
func UnionBy ¶
UnionBy unions the items in the given array by the given keys, such that each item in the resulting array has a unique combination of those keys. The first unique element is picked when deduplicating. The items in the resulting array are ordered deterministically (i.e unioning of array [x, y, z] and array [z, x, x, y], both return [x, y, z]).
E.g: Arguments: items: `[{"id": 1}, {"id": 2}, {"id": 1, "foo": "hello"}]`, keys: "id" Return: [{"id": 1}, {"id": 2}]
func UnnestArrays ¶
func UnnestArrays(c jsonutil.JSONContainer) (jsonutil.JSONArr, error)
UnnestArrays takes a json object with nested arrays (e.g.: {"key1": [{}...], "key2": {}}) and returns an unnested array that contains the top level key in the "k" field and each array element, unnested, in the "v" field (e.g.: [{"k": "key1", "v": {}} ...]). If the value of a key is an object, it simply returns that object. The output is sorted by the keys, and the array ordering is preserved. If the nested array is empty, the key is ignored.
E.g: c: `{"key1":[{"a": "z"}, {"b": "y"}], "key2": {"c": "x"}, "key3": []} return: [{"k": "key1", "v":{"a": "z"}}`, {"k": "key1", "v":{"b": "y"}}, {"k": "key2", "v":{"c": "x"}}]
Types ¶
This section is empty.