transform

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: MPL-2.0 Imports: 16 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstantValue

func ConstantValue(_ context.Context, d *TransformData) (interface{}, error)

ConstantValue :: intended for the start of a transform chain return the value passed as d.Param

func EnsureStringArray added in v0.1.1

func EnsureStringArray(_ context.Context, d *TransformData) (interface{}, error)

EnsureStringArray :: convert the input value to a string array

func FieldValue

func FieldValue(_ context.Context, d *TransformData) (interface{}, error)

FieldValue :: intended for the start of a transform chain return a field value of either the hydrate call result (if present) or the root item if not the field name is in the 'Param'

func FieldValueCamelCase

func FieldValueCamelCase(ctx context.Context, d *TransformData) (interface{}, error)

FieldValueCamelCase :: intended for the start of a transform chain convert the column name to camel case and call FieldValue

func FieldValueGo

func FieldValueGo(ctx context.Context, d *TransformData) (interface{}, error)

FieldValueGo :: intended for the start of a transform chain convert the column name to camel case, with common initialisms upper case, and call FieldValue

func FieldValueTag

func FieldValueTag(ctx context.Context, d *TransformData) (interface{}, error)

FieldValueTag :: intended for the start of a transform chain find the data value with the tag matching the column name

func MatrixItemValue added in v0.2.0

func MatrixItemValue(ctx context.Context, d *TransformData) (interface{}, error)

MatrixItemValue :: intended for the start of a transform chain retrieve a value from the matrix item, using the param as key

func MethodValue

func MethodValue(_ context.Context, d *TransformData) (interface{}, error)

func NullIfEqualParam

func NullIfEqualParam(_ context.Context, d *TransformData) (interface{}, error)

NullIfEqualParam :: if the input Value equals the transform param, return nil

func NullIfZeroValue

func NullIfZeroValue(_ context.Context, d *TransformData) (interface{}, error)

NullIfZero :: if the input value equals the zero value of its type, return nil

func RawValue

func RawValue(_ context.Context, d *TransformData) (interface{}, error)

RawValue :: intended for the start of a transform chain return the whole hydrate item

func StringArrayToMap added in v0.1.1

func StringArrayToMap(_ context.Context, d *TransformData) (interface{}, error)

StringArrayToMap :: converts a string array to a map where the keys are the array elements

func ToBool

func ToBool(_ context.Context, d *TransformData) (interface{}, error)

ToBool :: convert the (string) value to a bool if value is not a string, do nothing

func ToDouble

func ToDouble(_ context.Context, d *TransformData) (interface{}, error)

ToDouble :: convert the value to an float64

func ToInt

func ToInt(_ context.Context, d *TransformData) (interface{}, error)

ToInt :: convert the value to an int64

func ToLower

func ToLower(_ context.Context, d *TransformData) (interface{}, error)

ToLower :: convert the (string or *string) value to lower case if value is not a string, return unaltered value

func ToString

func ToString(_ context.Context, d *TransformData) (interface{}, error)

ToString :: convert the value to a string

func ToUpper

func ToUpper(_ context.Context, d *TransformData) (interface{}, error)

ToUpper :: convert the (string or *string) value to upper case if value is not a string, return unaltered value

func UnixMsToTimestamp

func UnixMsToTimestamp(_ context.Context, d *TransformData) (interface{}, error)

UnixMsToTimestamp :: convert unix time in milliseconds to RFC3339 format

func UnixToTimestamp

func UnixToTimestamp(_ context.Context, d *TransformData) (interface{}, error)

UnixToTimestamp :: convert unix time format to RFC3339 format

func UnmarshalYAML

func UnmarshalYAML(_ context.Context, d *TransformData) (interface{}, error)

UnmarshalYAML :: parse the yaml-encoded data and return the result

Types

type ColumnTransforms

type ColumnTransforms struct {
	// a list of transforms to apply to the data
	Transforms []*TransformCall
	// should this transform chain start with the default transform for the column
	ApplyDefaultTransform bool
}

ColumnTransforms :: a struct defining the data transforms required to map from a JSON value to a column value

func From

func From(transformFunc TransformFunc) *ColumnTransforms

Generate a value by calling 'transformFunc'

func FromCamel

func FromCamel() *ColumnTransforms

Generate a value by converting the given field name to camel case and retrieving from the source item

func FromConstant

func FromConstant(value interface{}) *ColumnTransforms

Return a constant value (specified by 'param')

func FromField

func FromField(field string) *ColumnTransforms

Generate a value by retrieving a field from the source item

func FromGo

func FromGo() *ColumnTransforms

Generate a value by converting the given field name to camel case and retrieving from the source item

func FromJSONTag

func FromJSONTag() *ColumnTransforms

Generate a value by finding a struct property with the json tag matching the column name

func FromMatrixItem added in v0.2.0

func FromMatrixItem(key string) *ColumnTransforms

func FromMethod

func FromMethod(methodName string) *ColumnTransforms

FromMethod invokes a function on the hydrate item

func FromP

func FromP(transformFunc TransformFunc, param interface{}) *ColumnTransforms

Generate a value by calling 'transformFunc' passing param

func FromTag

func FromTag(tagName string) *ColumnTransforms

Generate a value by finding a struct property with the tag 'tagName' matching the column name

func FromValue

func FromValue() *ColumnTransforms

Generate a value by returning the raw hydrate item

func (*ColumnTransforms) Execute

func (t *ColumnTransforms) Execute(ctx context.Context, hydrateItem interface{}, hydrateResults map[string]interface{}, defaultTransform *ColumnTransforms, columnName string) (interface{}, error)

func (*ColumnTransforms) NullIfEqual

func (t *ColumnTransforms) NullIfEqual(nullValue interface{}) *ColumnTransforms

NullValue :: if the input Value equals the transform param, return nil

func (*ColumnTransforms) NullIfZero

func (t *ColumnTransforms) NullIfZero() *ColumnTransforms

NullIfZero :: if the input value equals the zero value of its type, return nil

func (*ColumnTransforms) Transform

func (t *ColumnTransforms) Transform(transformFunc TransformFunc) *ColumnTransforms

Apply an arbitrary transform to the data (specified by 'transformFunc')

func (*ColumnTransforms) TransformP

func (t *ColumnTransforms) TransformP(transformFunc TransformFunc, param interface{}) *ColumnTransforms

Apply an arbitrary transform to the data, passing a parameter

type GetSourceFieldFunc

type GetSourceFieldFunc func(interface{}) string

type TransformCall

type TransformCall struct {
	Transform TransformFunc
	Param     interface{}
}

TransformCall :: a transform function and parameter to invoke it with

func (*TransformCall) Execute

func (tr *TransformCall) Execute(ctx context.Context, value interface{}, hydrateItem interface{}, hydrateResults map[string]interface{}, columnName string) (transformedValue interface{}, err error)

Execute :: execute a transform call

type TransformData

type TransformData struct {
	// an optional parameter
	Param interface{}
	// the value to be transformed
	Value interface{}
	// a data object containing the the source data for this column
	HydrateItem interface{}
	// all hydrate results
	HydrateResults map[string]interface{}
	// the column this transform is generating
	ColumnName string
	// the 'matrix item' associated with this row
	MatrixItem map[string]interface{}
}

TransformData :: the input to a transform function

type TransformFunc

type TransformFunc func(context.Context, *TransformData) (interface{}, error)

TransformFunc :: function to transform a data value from the api value to a column value parameters are: value, parent json object, param returns the transformed HydrateItem

Jump to

Keyboard shortcuts

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