customfuncs

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 8 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommonCustomFuncs = map[string]CustomFuncType{

	"coalesce":                Coalesce,
	"concat":                  Concat,
	"dateTimeLayoutToRFC3339": DateTimeLayoutToRFC3339,
	"dateTimeToEpoch":         DateTimeToEpoch,
	"dateTimeToRFC3339":       DateTimeToRFC3339,
	"epochToDateTimeRFC3339":  EpochToDateTimeRFC3339,
	"lower":                   Lower,
	"now":                     Now,
	"upper":                   Upper,
	"uuidv3":                  UUIDv3,
}

CommonCustomFuncs contains the most basic and frequently-used custom functions that are suitable for all versions of schemas.

Functions

func Coalesce

func Coalesce(_ *transformctx.Ctx, strs ...string) (string, error)

Coalesce returns the first non-empty string of the input strings. If no input strings are given or all of them are empty, then an empty string is returned. Note: a blank string (with only whitespaces) is not considered as empty.

func Concat

func Concat(_ *transformctx.Ctx, strs ...string) (string, error)

Concat concatenates a number of strings together. If no strings specified, "" is returned.

func DateTimeLayoutToRFC3339

func DateTimeLayoutToRFC3339(_ *transformctx.Ctx, datetime, layout, layoutTZ, fromTZ, toTZ string) (string, error)

DateTimeLayoutToRFC3339 parses a 'datetime' string according a given 'layout' and normalizes and returns it in RFC3339 format. 'layoutTZ' specifies whether the 'layout' contains timezone info (such as tz offset, tz short names lik 'PST', or standard IANA tz long name, such as 'America/Los_Angeles'); note 'layoutTZ' is a string with two possible values "true" or "false". 'fromTZ' is only used if 'datetime'/'layout' don't contain TZ info; if not specified, the parser will keep the original TZ (or lack of it) of 'datetime'. 'toTZ' decides what TZ the output RFC3339 date time will be in.

func DateTimeToEpoch

func DateTimeToEpoch(_ *transformctx.Ctx, datetime, fromTZ, unit string) (string, error)

DateTimeToEpoch parses a 'datetime' string intelligently, and returns its epoch number. 'fromTZ' is only used if 'datetime' doesn't contain TZ info; if not specified, the parser will keep the original TZ (or lack of it) of 'datetime'. 'unit' determines the time unit resolution of the output epoch number.

func DateTimeToRFC3339

func DateTimeToRFC3339(_ *transformctx.Ctx, datetime, fromTZ, toTZ string) (string, error)

DateTimeToRFC3339 parses a 'datetime' string intelligently, normalizes and returns it in RFC3339 format. 'fromTZ' is only used if 'datetime' doesn't contain TZ info; if not specified, the parser will keep the original TZ (or lack of it) of 'datetime'. 'toTZ' decides what TZ the output RFC3339 date time will be in.

func EpochToDateTimeRFC3339

func EpochToDateTimeRFC3339(_ *transformctx.Ctx, epoch, unit string, tz ...string) (string, error)

EpochToDateTimeRFC3339 translates the 'epoch' timestamp under the given 'unit' into an RFC3339 formatted datetime string in the given timezone 'tz', if specified.

func Lower

func Lower(_ *transformctx.Ctx, s string) (string, error)

Lower lowers the case of an input string.

func Now

func Now(_ *transformctx.Ctx) (string, error)

Now returns the current time in UTC in RFC3339 format.

func UUIDv3

func UUIDv3(_ *transformctx.Ctx, s string) (string, error)

UUIDv3 uses MD5 to produce a consistent/stable UUID for an input string.

func Upper

func Upper(_ *transformctx.Ctx, s string) (string, error)

Upper uppers the case of an input string.

Types

type CustomFuncType

type CustomFuncType = interface{}

CustomFuncType is the type of custom function. Has to use interface{} given we support non-variadic and variadic functions.

type CustomFuncs

type CustomFuncs = map[string]CustomFuncType

CustomFuncs is a map from custom func names to an actual custom func.

func Merge

func Merge(funcs ...CustomFuncs) CustomFuncs

Merge merges multiple custom func maps into one.

Jump to

Keyboard shortcuts

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