udf

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 13 Imported by: 9 modules, 8 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Expandable Collection User Defined Function

Usage
Data substitution

    aMap := data.NewMap();
    aMap.Put("ts", "2015-02-11")
    udf.Register(aMap)
    expanded := aMap.ExpandAsText(`$FormatTime($ts, "yyyy")`)
 
Data node selection

	holder := data.NewMap()
    collection := data.NewCollection()
    collection.Push(map[string]interface{}{
        "amount": 2,
        "id":2,
        "name":"p1",
        "vendor":"v1",
    })
    collection.Push(map[string]interface{}{
        "amount": 12,
        "id":3,
        "name":"p2",
        "vendor":"v2",
    })
    holder.SetValue("node1.obj", collection)

	records, err := Select([]interface{}{"node1/obj/*", "id", "name:product"}, holder)


The list of defined UDFs
  • Length, Len returns length of slice, map or string
  • AsMap - convert source into a map, it accepts data structure, or JSON, YAML literal
  • AsCollection - convert source into a slice, it accepts data structure, or JSON, YAML literal
  • AsData - convert source into a map or slice, it accepts data structure, or JSON, YAML literal
  • AsInt - convert source into a an int
  • AsFloat - convert source into a a float
  • AsBool - convert source into a boolean
  • AsNumber - converts to either int or float
  • FormatTime, takes two arguments, date or now, followed by java style date format
  • Values - returns map values
  • Keys - return map keys
  • IndexOf - returns index of matched slice element
  • Join - join slice element with supplied separator
  • Split - split text by separator
  • Sum - sums values for matched Path, i.e. $Sum('node1/obj/*/amount')
  • Count - counts values for matched Path, i.e. $Sum('node1/obj/*/amount')
  • Select - selects attribute for matched path, i.e $Select("node1/obj/*", "id", "name:product")
  • QueryEscape - url escape
  • QueryUnescape - url unescape
  • Base64Encode
  • Base64DecodeText
  • TrimSpace
  • Elapsed elapsed time
  • Rand
  • Replace
  • ToLower
  • ToUpper
  • AsNewLineDelimitedJSON

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Predefined = data.Map{
	"AsInt":                  AsInt,
	"AsString":               AsString,
	"AsFloat":                AsFloat,
	"AsFloat32":              AsFloat32,
	"AsFloat32Ptr":           AsFloat32Ptr,
	"AsBool":                 AsBool,
	"AsMap":                  AsMap,
	"AsData":                 AsData,
	"AsCollection":           AsCollection,
	"AsJSON":                 AsJSON,
	"Type":                   Type,
	"Join":                   Join,
	"Split":                  Split,
	"Keys":                   Keys,
	"StringKeys":             StringKeys,
	"Values":                 Values,
	"Length":                 Length,
	"Len":                    Length,
	"IndexOf":                IndexOf,
	"FormatTime":             FormatTime,
	"QueryEscape":            QueryEscape,
	"QueryUnescape":          QueryUnescape,
	"Base64Encode":           Base64Encode,
	"Base64Decode":           Base64Decode,
	"Base64RawURLEncode":     Base64RawURLEncode,
	"Base64RawURLDecode":     Base64RawURLDecode,
	"Base64DecodeText":       Base64DecodeText,
	"TrimSpace":              TrimSpace,
	"Elapsed":                Elapsed,
	"Sum":                    Sum,
	"Count":                  Count,
	"AsNumber":               AsNumber,
	"Select":                 Select,
	"Rand":                   Rand,
	"Concat":                 Concat,
	"Merge":                  Merge,
	"AsStringMap":            AsStringMap,
	"PackInt32sTo64":         PackInt32sTo64,
	"Replace":                Replace,
	"ToLower":                ToLower,
	"ToUpper":                ToUpper,
	"AsNewLineDelimitedJSON": AsNewLineDelimitedJSON,
	"LoadJSON":               LoadJSON,
}

Functions

func AsBool

func AsBool(source interface{}, state data.Map) (interface{}, error)

AsBool converts source into bool

func AsCollection

func AsCollection(source interface{}, state data.Map) (interface{}, error)

AsCollection converts source into a slice

func AsData

func AsData(source interface{}, state data.Map) (interface{}, error)

AsData converts source into map or slice

func AsFloat

func AsFloat(source interface{}, state data.Map) (interface{}, error)

AsFloat converts source into float64

func AsFloat32 added in v0.19.1

func AsFloat32(source interface{}, state data.Map) (interface{}, error)

AsFloat32 converts source into float32

func AsFloat32Ptr added in v0.19.1

func AsFloat32Ptr(source interface{}, state data.Map) (interface{}, error)

AsFloat32 converts source into float32

func AsInt

func AsInt(source interface{}, state data.Map) (interface{}, error)

AsInt converts source into int

func AsJSON added in v0.7.0

func AsJSON(source interface{}, state data.Map) (interface{}, error)

AsJSON converts source to JSON

func AsMap

func AsMap(source interface{}, state data.Map) (interface{}, error)

AsMap converts source into map

func AsNewLineDelimitedJSON added in v0.31.2

func AsNewLineDelimitedJSON(source interface{}, state data.Map) (interface{}, error)

AsNewLineDelimitedJSON convers a slice into new line delimited JSON

func AsNumber added in v0.15.0

func AsNumber(value interface{}, state data.Map) (interface{}, error)

AsNumber return int or float

func AsString

func AsString(source interface{}, state data.Map) (interface{}, error)

AsInt converts source into int

func AsStringMap added in v0.18.2

func AsStringMap(source interface{}, state data.Map) (interface{}, error)

AsStringMap returns map[string]string

func Base64Decode added in v0.6.6

func Base64Decode(source interface{}, state data.Map) (interface{}, error)

Base64Decode decodes source using base64.StdEncoding

func Base64DecodeText added in v0.7.0

func Base64DecodeText(source interface{}, state data.Map) (interface{}, error)

Base64DecodeText decodes source using base64.StdEncoding to string

func Base64Encode added in v0.6.6

func Base64Encode(source interface{}, state data.Map) (interface{}, error)

Base64Decode encodes source using base64.StdEncoding

func Base64RawURLDecode added in v0.35.0

func Base64RawURLDecode(source interface{}, state data.Map) (interface{}, error)

Base64RawURLDecode decodes source using base64.RawURLEncoding

func Base64RawURLEncode added in v0.35.0

func Base64RawURLEncode(source interface{}, state data.Map) (interface{}, error)

Base64RawURLEncode encodes source using base64.RawURLEncoding

func Concat added in v0.18.0

func Concat(params interface{}, state data.Map) (interface{}, error)

Concat concatenate supplied parameters, parameters

func Count added in v0.15.0

func Count(xPath interface{}, state data.Map) (interface{}, error)

Count returns count of matched nodes leaf value

func Elapsed added in v0.15.0

func Elapsed(source interface{}, state data.Map) (interface{}, error)

Elapsed returns elapsed time

func FormatTime

func FormatTime(source interface{}, state data.Map) (interface{}, error)

FormatTime return formatted time, it takes an array of arguments, the first is time express, or now followed by java style time format, optional timezone and truncate format .

func IndexOf

func IndexOf(source interface{}, state data.Map) (interface{}, error)

IndexOf returns index of the matched slice elements or -1

func Join

func Join(args interface{}, state data.Map) (interface{}, error)

Join joins slice by separator

func Keys

func Keys(source interface{}, state data.Map) (interface{}, error)

Keys returns keys of the supplied map

func Length

func Length(source interface{}, state data.Map) (interface{}, error)

Length returns length of slice or string

func LoadJSON added in v0.32.0

func LoadJSON(source interface{}, state data.Map) (interface{}, error)

LoadJSON loads new line delimited or regular JSON into data structure

func Merge added in v0.18.0

func Merge(params interface{}, state data.Map) (interface{}, error)

Merge creates a new merged map for supplied maps, (mapOrPath1, mapOrPath2, mapOrPathN)

func PackInt32sTo64 added in v0.38.0

func PackInt32sTo64(source interface{}, state data.Map) (interface{}, error)

PackInt32sTo64 returns args<<32|args

func QueryEscape

func QueryEscape(source interface{}, state data.Map) (interface{}, error)

QueryEscape returns url escaped text

func QueryUnescape added in v0.8.1

func QueryUnescape(source interface{}, state data.Map) (interface{}, error)

QueryUnescape returns url escaped text

func Rand added in v0.17.1

func Rand(params interface{}, state data.Map) (interface{}, error)

Rand returns random

func Register

func Register(aMap data.Map)

func Replace added in v0.29.0

func Replace(source interface{}, state data.Map) (interface{}, error)

Replace replaces text with old and new fragments

func Select added in v0.17.0

func Select(params interface{}, state data.Map) (interface{}, error)

Select returns all matched attributes from matched nodes, attributes can be alised with sourcePath:alias

func Split added in v0.23.8

func Split(args interface{}, state data.Map) (interface{}, error)

Split split text to build a slice

func StringKeys added in v0.35.0

func StringKeys(source interface{}, state data.Map) (interface{}, error)

Keys returns keys of the supplied map

func Sum added in v0.15.0

func Sum(xPath interface{}, state data.Map) (interface{}, error)

Sum returns sums of matched nodes leaf value

func ToLower added in v0.31.1

func ToLower(source interface{}, state data.Map) (interface{}, error)

Lower converts string to lower case

func ToUpper added in v0.31.1

func ToUpper(source interface{}, state data.Map) (interface{}, error)

Lower converts string to upper case

func TrimSpace added in v0.11.1

func TrimSpace(source interface{}, state data.Map) (interface{}, error)

TrimSpace returns trims spaces from supplied text

func Type added in v0.7.0

func Type(source interface{}, state data.Map) (interface{}, error)

Type returns source type

func Values

func Values(source interface{}, state data.Map) (interface{}, error)

Values returns values of the supplied map

Types

type Doc added in v0.20.3

type Doc struct {
	Description string
	Example     string
}

Doc udf documentation

Jump to

Keyboard shortcuts

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