Documentation ¶
Overview ¶
Transform package provides the ability to transform data from APIs. It contains transform functions which can be chained together to get the desired values
Index ¶
- func ConstantValue(_ context.Context, d *TransformData) (interface{}, error)
- func EnsureStringArray(_ context.Context, d *TransformData) (interface{}, error)
- func FieldValue(_ context.Context, d *TransformData) (interface{}, error)
- func FieldValueCamelCase(ctx context.Context, d *TransformData) (interface{}, error)
- func FieldValueGo(ctx context.Context, d *TransformData) (interface{}, error)
- func FieldValueTag(ctx context.Context, d *TransformData) (interface{}, error)
- func MatrixItemValue(ctx context.Context, d *TransformData) (interface{}, error)
- func MethodValue(_ context.Context, d *TransformData) (interface{}, error)
- func NullIfEqualParam(_ context.Context, d *TransformData) (interface{}, error)
- func NullIfZeroValue(_ context.Context, d *TransformData) (interface{}, error)
- func QualValue(ctx context.Context, d *TransformData) (interface{}, error)
- func RawValue(_ context.Context, d *TransformData) (interface{}, error)
- func StringArrayToMap(_ context.Context, d *TransformData) (interface{}, error)
- func ToBool(_ context.Context, d *TransformData) (interface{}, error)
- func ToDouble(_ context.Context, d *TransformData) (interface{}, error)
- func ToInt(_ context.Context, d *TransformData) (interface{}, error)
- func ToLower(_ context.Context, d *TransformData) (interface{}, error)
- func ToString(_ context.Context, d *TransformData) (interface{}, error)
- func ToUpper(_ context.Context, d *TransformData) (interface{}, error)
- func UnixMsToTimestamp(_ context.Context, d *TransformData) (interface{}, error)
- func UnixToTimestamp(_ context.Context, d *TransformData) (interface{}, error)
- func UnmarshalYAML(_ context.Context, d *TransformData) (interface{}, error)
- type ColumnTransforms
- func From(transformFunc TransformFunc) *ColumnTransforms
- func FromCamel() *ColumnTransforms
- func FromConstant(value interface{}) *ColumnTransforms
- func FromField(fieldNames ...string) *ColumnTransforms
- func FromGo() *ColumnTransforms
- func FromJSONTag() *ColumnTransforms
- func FromMatrixItem(key string) *ColumnTransforms
- func FromMethod(methodName string) *ColumnTransforms
- func FromP(transformFunc TransformFunc, param interface{}) *ColumnTransforms
- func FromQual(qual string) *ColumnTransforms
- func FromTag(tagName string) *ColumnTransforms
- func FromValue() *ColumnTransforms
- func (t *ColumnTransforms) Execute(ctx context.Context, transformData *TransformData) (interface{}, error)
- func (t *ColumnTransforms) NullIfEqual(nullValue interface{}) *ColumnTransforms
- func (t *ColumnTransforms) NullIfZero() *ColumnTransforms
- func (t *ColumnTransforms) Transform(transformFunc TransformFunc) *ColumnTransforms
- func (t *ColumnTransforms) TransformP(transformFunc TransformFunc, param interface{}) *ColumnTransforms
- type GetSourceFieldFunc
- type TransformCall
- type TransformData
- type TransformFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConstantValue ¶
func ConstantValue(_ context.Context, d *TransformData) (interface{}, error)
ConstantValue is intended for the start of a transform chain This returns the value passed as d.Param
func EnsureStringArray ¶
func EnsureStringArray(_ context.Context, d *TransformData) (interface{}, error)
EnsureStringArray convert the input value from transform data into a string array
func FieldValue ¶
func FieldValue(_ context.Context, d *TransformData) (interface{}, error)
FieldValue function is intended for the start of a transform chain. This returns a field value of either the hydrate call result (if present) or the root item if not the 'Param' is a list of field names - Each field is tried in turn. If the property does not exist or is nil, the next field is tried
func FieldValueCamelCase ¶
func FieldValueCamelCase(ctx context.Context, d *TransformData) (interface{}, error)
FieldValueCamelCase is intended for the start of a transform chain This converts the column name to camel case and call FieldValue
func FieldValueGo ¶
func FieldValueGo(ctx context.Context, d *TransformData) (interface{}, error)
FieldValueGo is intended for the start of a transform chain This converts 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 is intended for the start of a transform chain This finds the data value with the tag matching the column name
func MatrixItemValue ¶
func MatrixItemValue(ctx context.Context, d *TransformData) (interface{}, error)
MatrixItemValue is intended for the start of a transform chain This retrieves a value from the matrix item, using the param from transform data as a key
func MethodValue ¶
func MethodValue(_ context.Context, d *TransformData) (interface{}, error)
MethodValue function takes the transform data and invokes specified method on the hydrate item
func NullIfEqualParam ¶
func NullIfEqualParam(_ context.Context, d *TransformData) (interface{}, error)
NullIfEqualParam returns nil if the input Value equals the transform param
func NullIfZeroValue ¶
func NullIfZeroValue(_ context.Context, d *TransformData) (interface{}, error)
NullIfZeroValue takes the transform data and returns nil if the input value equals the zero value of its type
func QualValue ¶
func QualValue(ctx context.Context, d *TransformData) (interface{}, error)
QualValue takes the column name from the transform data param and retrieves any quals for it If the quals is a single equals quals it returns it If there are any other quals and error is returned
func RawValue ¶
func RawValue(_ context.Context, d *TransformData) (interface{}, error)
RawValue is intended for the start of a transform chain This returns the whole hydrate item as it is
func StringArrayToMap ¶
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 converts the (string) value to a bool This returns nil if value is not a string
func ToDouble ¶
func ToDouble(_ context.Context, d *TransformData) (interface{}, error)
ToDouble convert the value from transform data to float64
func ToInt ¶
func ToInt(_ context.Context, d *TransformData) (interface{}, error)
ToInt convert the value from transform data to an int64
func ToLower ¶
func ToLower(_ context.Context, d *TransformData) (interface{}, error)
ToLower converts the (string or *string) value to lower case returns unaltered value if value is not a string
func ToString ¶
func ToString(_ context.Context, d *TransformData) (interface{}, error)
ToString convert the value from transform data to a string
func ToUpper ¶
func ToUpper(_ context.Context, d *TransformData) (interface{}, error)
ToUpper converts the (string or *string) value to upper case, returns unaltered value if value from the transform data is not a string
func UnixMsToTimestamp ¶
func UnixMsToTimestamp(_ context.Context, d *TransformData) (interface{}, error)
UnixMsToTimestamp convert unix time in milliseconds to go time object (which will later be converted to RFC3339 format by the FDW)
func UnixToTimestamp ¶
func UnixToTimestamp(_ context.Context, d *TransformData) (interface{}, error)
UnixToTimestamp convert unix time format to go time object (which will later be converted to RFC3339 format by the FDW)
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 }
ColumnTransforms struct defines the data transforms required to map from a JSON value to a column value
func From ¶
func From(transformFunc TransformFunc) *ColumnTransforms
From generate a value by calling 'transformFunc'
func FromCamel ¶
func FromCamel() *ColumnTransforms
FromCamel generates a value by converting the given field name to camel case and retrieving from the source item
func FromConstant ¶
func FromConstant(value interface{}) *ColumnTransforms
FromConstant returns a constant value (specified by 'param')
func FromField ¶
func FromField(fieldNames ...string) *ColumnTransforms
FromField generates a value by retrieving a field or a set of fields from the source item
func FromGo ¶
func FromGo() *ColumnTransforms
FromGo generates a value by converting the given field name to camel case and retrieving from the source item
func FromJSONTag ¶
func FromJSONTag() *ColumnTransforms
FromJSONTag generates a value by finding a struct property with the json tag matching the column name
func FromMatrixItem ¶
func FromMatrixItem(key string) *ColumnTransforms
FromMatrixItem takes key from transform data and generates the value from Matrix Items
func FromMethod ¶
func FromMethod(methodName string) *ColumnTransforms
FromMethod invokes a function on the hydrate item coming from transform data
func FromP ¶
func FromP(transformFunc TransformFunc, param interface{}) *ColumnTransforms
FromP generates a value by calling 'transformFunc' passing param
func FromQual ¶
func FromQual(qual string) *ColumnTransforms
FromQual takes the specific column and generates it's values from key column quals
func FromTag ¶
func FromTag(tagName string) *ColumnTransforms
FromTag generates a value by finding a struct property with the tag 'tagName' matching the column name
func FromValue ¶
func FromValue() *ColumnTransforms
FromValue generates a value by returning the raw hydrate item
func (*ColumnTransforms) Execute ¶
func (t *ColumnTransforms) Execute(ctx context.Context, transformData *TransformData) (interface{}, error)
func (*ColumnTransforms) NullIfEqual ¶
func (t *ColumnTransforms) NullIfEqual(nullValue interface{}) *ColumnTransforms
NullIfEqual returns nil if the input Value equals the transform param
func (*ColumnTransforms) NullIfZero ¶
func (t *ColumnTransforms) NullIfZero() *ColumnTransforms
NullIfZero returns nil if the input value equals the zero value of its type
func (*ColumnTransforms) Transform ¶
func (t *ColumnTransforms) Transform(transformFunc TransformFunc) *ColumnTransforms
Transform function applies an arbitrary transform to the data (specified by 'transformFunc')
func (*ColumnTransforms) TransformP ¶
func (t *ColumnTransforms) TransformP(transformFunc TransformFunc, param interface{}) *ColumnTransforms
TransformP function applies 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 is a transform function and parameter to invoke it with
func (*TransformCall) Execute ¶
func (tr *TransformCall) Execute(ctx context.Context, value interface{}, transformData *TransformData) (transformedValue interface{}, err error)
Execute function executes 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 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{} // KeyColumnQuals will be populated with the quals as a map of column name to an array of quals for that column KeyColumnQuals map[string]quals.QualSlice }
TransformData is the input to a transform function.
type TransformFunc ¶
type TransformFunc func(context.Context, *TransformData) (interface{}, error)
TransformFunc is a 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