model

package
v0.0.0-...-42bca81 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0, Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ANSIC regex to validate ANSIC date string
	ANSIC = `` /* 129-byte string literal not displayed */
	// UnixDate regex to validate UnixDate date string
	UnixDate = `` /* 133-byte string literal not displayed */
	// RubyDate regex to validate RubyDate date string
	RubyDate = `` /* 140-byte string literal not displayed */
	// RFC822 regex to validate RFC822 date string
	RFC822 = `^[0-9]{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{2} [0-9]{2}:[0-9]{2} MST$`
	// RFC822Z regex to validate RFC822Z date string
	RFC822Z = `^[0-9]{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{2} [0-9]{2}:[0-9]{2} \-?[0-9]{4}$` // RFC822 with numeric zone
	// RFC850 regex to validate RFC850 date string
	RFC850 = `` /* 160-byte string literal not displayed */
	// RFC1123 regex to validate RFC1123 date string
	RFC1123 = `` /* 131-byte string literal not displayed */
	// RFC1123Z regex to validate RFC1123Z date string
	RFC1123Z = `` // RFC1123 with numeric zone
	/* 139-byte string literal not displayed */
	// RFC3339 regex to validate RFC3339 date string
	RFC3339 = `^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z[0-9]{2}:[0-9]{2}$`
	// RFC3339Nano regex to validate RFC3339Nano date string
	RFC3339Nano = `^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{2}Z[0-9]{2}:[0-9]{2}$`
	// Kitchen regex to validate Kitchen date string
	Kitchen = `^[0-1]?[0-9]:[0-9]{2}(AM|PM)$`
	// Stamp regex to validate Stamp date string
	Stamp = `^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]?[0-9] [0-9]{2}:[0-9]{2}:[0-9]{2}$`
	// StampMilli regex to validate StampMilli date string
	StampMilli = `^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]?[0-9] [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}$`
	// StampMicro regex to validate StampMicro date string
	StampMicro = `^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]?[0-9] [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{6}$`
	// StampNano regex to validate StampNano date string
	StampNano = `^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]?[0-9] [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{9}$`
)

Variables

View Source
var (
	// DateTimeLayout contains the date time layouting used by this data access layer.
	DateTimeLayout = time.RFC3339
)

Functions

func ArrMapLen

func ArrMapLen(arr reflect.Value, arg []reflect.Value) (reflect.Value, error)

ArrMapLen will return the size of underlying map, array or slice

func IsDateFormatValid

func IsDateFormatValid(layout, date string) bool

IsDateFormatValid validate if the supplied date string is compatible with specified format. the format should come from standard time format (eg. time.RFC3339, time.ANSIC, time.ANSIC, time.RFC850, etc)

func SetNumberValue

func SetNumberValue(target, newvalue reflect.Value) error

SetNumberValue will assign a numeric value to a numeric target value this helper function is to ensure assignment between numerical types is happening regardless of types, int, uint or float. The rule designer should be careful as conversion of types in automatic way like this will cause lost of precision during conversion. This will be removed in the future version.

func StrCompare

func StrCompare(str string, arg []reflect.Value) (reflect.Value, error)

StrCompare is like strings.compare() function, to be called by the ValueNode function call if the underlying data is string.

func StrContains

func StrContains(str string, arg []reflect.Value) (reflect.Value, error)

StrContains is like strings.Contains() function, to be called by the ValueNode function call if the underlying data is string. is like strings.compare() function, to be called by the ValueNode functioncall if the underlying data is string.

func StrCount

func StrCount(str string, arg []reflect.Value) (reflect.Value, error)

StrCount is like strings.Count() function, to be called by the ValueNode function call if the underlying data is string.

func StrHasPrefix

func StrHasPrefix(str string, arg []reflect.Value) (reflect.Value, error)

StrHasPrefix is like strings.HasPrefix() function, to be called by the ValueNode functioncall if the underlying data is string.

func StrHasSuffix

func StrHasSuffix(str string, arg []reflect.Value) (reflect.Value, error)

StrHasSuffix is like strings.HasSuffix() function, to be called by the ValueNode functioncall if the underlying data is string.

func StrIn

func StrIn(str string, arg []reflect.Value) (reflect.Value, error)

StrIn will check the string instance if its equals one of the arguments, if no argument specified it will return false

func StrIndex

func StrIndex(str string, arg []reflect.Value) (reflect.Value, error)

StrIndex is like strings.Index() function, to be called by the ValueNode functioncall if the underlying data is string.

func StrLastIndex

func StrLastIndex(str string, arg []reflect.Value) (reflect.Value, error)

StrLastIndex is like strings.LastIndex() function, to be called by the ValueNode functioncall if the underlying data is string.

func StrLen

func StrLen(str string, arg []reflect.Value) (reflect.Value, error)

StrLen is return the string length value

func StrMatchRegexPattern

func StrMatchRegexPattern(str string, arg []reflect.Value) (reflect.Value, error)

StrMatchRegexPattern reports whether the string s contains any match of the regular expression pattern.

func StrRepeat

func StrRepeat(str string, arg []reflect.Value) (reflect.Value, error)

StrRepeat is like strings.Repeat() function, to be called by the ValueNode functioncall if the underlying data is string.

func StrReplace

func StrReplace(str string, arg []reflect.Value) (reflect.Value, error)

StrReplace is like strings.Replace() function, to be called by the ValueNode functioncall if the underlying data is string.

func StrSplit

func StrSplit(str string, arg []reflect.Value) (reflect.Value, error)

StrSplit is like strings.Split() function, to be called by the ValueNode functioncall if the underlying data is string.

func StrToLower

func StrToLower(str string, arg []reflect.Value) (reflect.Value, error)

StrToLower is like strings.ToLower() function, to be called by the ValueNode functioncall if the underlying data is string.

func StrToUpper

func StrToUpper(str string, arg []reflect.Value) (reflect.Value, error)

StrToUpper is like strings.ToUpper() function, to be called by the ValueNode functioncall if the underlying data is string.

func StrTrim

func StrTrim(str string, arg []reflect.Value) (reflect.Value, error)

StrTrim is like strings.Trim() function, to be called by the ValueNode functioncall if the underlying data is string.

Types

type GoValueNode

type GoValueNode struct {
	// contains filtered or unexported fields
}

GoValueNode is an implementation of ValueNode that used to traverse native golang primitives through reflect package

func (*GoValueNode) AppendValue

func (node *GoValueNode) AppendValue(value []reflect.Value) (err error)

AppendValue will append the new values into the current underlying array. will \n\nreturn error if argument list are not compatible with the array element type.

func (*GoValueNode) CallFunction

func (node *GoValueNode) CallFunction(funcName string, args ...reflect.Value) (retval reflect.Value, err error)

CallFunction will call a function owned by the underlying value receiver. this function will artificially create a built-in functions for constants, array and map.

func (*GoValueNode) ContinueWithValue

func (node *GoValueNode) ContinueWithValue(value reflect.Value, identifiedAs string) ValueNode

ContinueWithValue will return a nother ValueNode to wrap the specified value and treated as child of current node. The main purpose of this is for easier debugging.

func (*GoValueNode) GetArrayType

func (node *GoValueNode) GetArrayType() (reflect.Type, error)

GetArrayType to get the type of underlying value array element types.

func (*GoValueNode) GetArrayValueAt

func (node *GoValueNode) GetArrayValueAt(index int) (val reflect.Value, err error)

GetArrayValueAt to get the value of an array element if the current underlying value is an array

func (*GoValueNode) GetChildNodeByField

func (node *GoValueNode) GetChildNodeByField(field string) (ValueNode, error)

GetChildNodeByField will retrieve the underlying struct's field and \n\nreturn the ValueNode wraper.

func (*GoValueNode) GetChildNodeByIndex

func (node *GoValueNode) GetChildNodeByIndex(index int) (ValueNode, error)

GetChildNodeByIndex is similar to `GetArrayValueAt`, where this will \n\nreturn a ValueNode that wrap the value.

func (*GoValueNode) GetChildNodeBySelector

func (node *GoValueNode) GetChildNodeBySelector(index reflect.Value) (ValueNode, error)

GetChildNodeBySelector is similar to GetMapValueAt, it retrieve a value of map element identified by a value index as ValueNode.

func (*GoValueNode) GetMapValueAt

func (node *GoValueNode) GetMapValueAt(index reflect.Value) (reflect.Value, error)

GetMapValueAt will retrieve a map value by the specified key argument.

func (*GoValueNode) GetObjectTypeByField

func (node *GoValueNode) GetObjectTypeByField(field string) (typ reflect.Type, err error)

GetObjectTypeByField will return underlying type of the value's field

func (*GoValueNode) GetObjectValueByField

func (node *GoValueNode) GetObjectValueByField(field string) (reflect.Value, error)

GetObjectValueByField will \n\nreturn underlying value's field

func (*GoValueNode) GetType

func (node *GoValueNode) GetType() (reflect.Type, error)

GetType will \n\nreturn the underlying value's type

func (*GoValueNode) GetValue

func (node *GoValueNode) GetValue() (reflect.Value, error)

GetValue will \n\nreturn the underlying reflect.Value

func (*GoValueNode) HasParent

func (node *GoValueNode) HasParent() bool

HasParent \n\nreturns `true` if the current value is a field, function, map, array, slice of another value

func (*GoValueNode) IdentifiedAs

func (node *GoValueNode) IdentifiedAs() string

IdentifiedAs \n\nreturn the current representation of this Value Node

func (*GoValueNode) IsArray

func (node *GoValueNode) IsArray() bool

IsArray to check if the underlying value is an array or not

func (*GoValueNode) IsBool

func (node *GoValueNode) IsBool() bool

IsBool will check if the underlying value is a type of boolean.

func (*GoValueNode) IsInteger

func (node *GoValueNode) IsInteger() bool

IsInteger will check if the underlying value is a type of int, or uint

func (*GoValueNode) IsInterface

func (node *GoValueNode) IsInterface() bool

func (*GoValueNode) IsMap

func (node *GoValueNode) IsMap() bool

IsMap will validate if the underlying value is a map.

func (*GoValueNode) IsObject

func (node *GoValueNode) IsObject() bool

IsObject will check if the underlying value is a struct or pointer to a struct

func (*GoValueNode) IsReal

func (node *GoValueNode) IsReal() bool

IsReal will check if the underlying value is a type of real number, float.

func (*GoValueNode) IsString

func (node *GoValueNode) IsString() bool

IsString will check if the underlying value is a type of string

func (*GoValueNode) IsTime

func (node *GoValueNode) IsTime() bool

IsTime will check if the underlying value is a time.Time

func (*GoValueNode) Length

func (node *GoValueNode) Length() (int, error)

Length will \n\nreturn the length of underlying value if its an array, slice, map or string

func (*GoValueNode) Parent

func (node *GoValueNode) Parent() ValueNode

Parent \n\nreturns the value node of the parent value, if this node is a field, function, map, array, slice of another value

func (*GoValueNode) SetArrayValueAt

func (node *GoValueNode) SetArrayValueAt(index int, value reflect.Value) (err error)

SetArrayValueAt will set the value of specified array index on the current underlying array value.

func (*GoValueNode) SetMapValueAt

func (node *GoValueNode) SetMapValueAt(index, newValue reflect.Value) (err error)

SetMapValueAt will set the map value for the specified key, value argument

func (*GoValueNode) SetObjectValueByField

func (node *GoValueNode) SetObjectValueByField(field string, newValue reflect.Value) (err error)

SetObjectValueByField will set the underlying value's field with new value.

func (*GoValueNode) Value

func (node *GoValueNode) Value() reflect.Value

Value \n\nreturns the underlying reflect.Value

type JSONValueNode

type JSONValueNode struct {
	// contains filtered or unexported fields
}

JSONValueNode will hold the json root object as the result of JSON unmarshal

func (*JSONValueNode) AppendValue

func (vn *JSONValueNode) AppendValue(value []reflect.Value) error

AppendValue will append an array of reflect.Value(s) into the end of this array/slice node. It will return error if its not an array nor slice.

func (*JSONValueNode) CallFunction

func (vn *JSONValueNode) CallFunction(funcName string, args ...reflect.Value) (reflect.Value, error)

CallFunction will always return an error, as Json data do not have any function in them.

func (*JSONValueNode) ContinueWithValue

func (vn *JSONValueNode) ContinueWithValue(value reflect.Value, identifiedAs string) ValueNode

ContinueWithValue will return a new node contains the specified value and the parent will be this value.

func (*JSONValueNode) GetArrayType

func (vn *JSONValueNode) GetArrayType() (reflect.Type, error)

GetArrayType return the content of an array. Since json array can contain any type, it will aways return type of nil.

func (*JSONValueNode) GetArrayValueAt

func (vn *JSONValueNode) GetArrayValueAt(index int) (reflect.Value, error)

GetArrayValueAt return the value of array element specified by index. It will return error if this node is not array or slice.

func (*JSONValueNode) GetChildNodeByField

func (vn *JSONValueNode) GetChildNodeByField(field string) (ValueNode, error)

GetChildNodeByField will return the field ValueNode

func (*JSONValueNode) GetChildNodeByIndex

func (vn *JSONValueNode) GetChildNodeByIndex(index int) (ValueNode, error)

GetChildNodeByIndex will return the array node of array element specified by index. It will return error if its not an array nor slice.

func (*JSONValueNode) GetChildNodeBySelector

func (vn *JSONValueNode) GetChildNodeBySelector(index reflect.Value) (ValueNode, error)

GetChildNodeBySelector get the ValueNode

func (*JSONValueNode) GetMapValueAt

func (vn *JSONValueNode) GetMapValueAt(index reflect.Value) (reflect.Value, error)

GetMapValueAt get the value of this map node at specific index/selector value. In json, the index selector must be of type of string.

func (*JSONValueNode) GetObjectTypeByField

func (vn *JSONValueNode) GetObjectTypeByField(field string) (reflect.Type, error)

GetObjectTypeByField get the type of the value by specified field. Since in json any field could store any field and there are no definition of what type on any field, this function will always return value of nil

func (*JSONValueNode) GetObjectValueByField

func (vn *JSONValueNode) GetObjectValueByField(field string) (reflect.Value, error)

GetObjectValueByField get the value of this node by the specified field.

func (*JSONValueNode) GetType

func (vn *JSONValueNode) GetType() (reflect.Type, error)

GetType return the reflect.Type of the value in this node

func (*JSONValueNode) GetValue

func (vn *JSONValueNode) GetValue() (reflect.Value, error)

GetValue same as Value()

func (*JSONValueNode) HasParent

func (vn *JSONValueNode) HasParent() bool

HasParent will return true if this node has parent node, other wise return false

func (*JSONValueNode) IdentifiedAs

func (vn *JSONValueNode) IdentifiedAs() string

IdentifiedAs will return the node label

func (*JSONValueNode) IsArray

func (vn *JSONValueNode) IsArray() bool

IsArray will validate if this node's value is of kind Array or Slice

func (*JSONValueNode) IsBool

func (vn *JSONValueNode) IsBool() bool

IsBool return true if the value of this node contains a boolean.

func (*JSONValueNode) IsInteger

func (vn *JSONValueNode) IsInteger() bool

IsInteger return true if the value of this node is conform to an integer. (no floating point value).

func (*JSONValueNode) IsInterface

func (vn *JSONValueNode) IsInterface() bool

func (*JSONValueNode) IsMap

func (vn *JSONValueNode) IsMap() bool

IsMap will validate if this node is a map.

func (*JSONValueNode) IsObject

func (vn *JSONValueNode) IsObject() bool

IsObject returns true if this node is an object or map.

func (*JSONValueNode) IsReal

func (vn *JSONValueNode) IsReal() bool

IsReal return true if the value of this node contains integer or floating point.

func (*JSONValueNode) IsString

func (vn *JSONValueNode) IsString() bool

IsString returns true if the value of this node contains a string.

func (*JSONValueNode) IsTime

func (vn *JSONValueNode) IsTime() bool

IsTime return true if the value of this node is of type string with specified DateTimeLayout

func (*JSONValueNode) Length

func (vn *JSONValueNode) Length() (l int, e error)

Length return the length of this node. It will return error if not type of string, map, array/slice or object.

func (*JSONValueNode) Parent

func (vn *JSONValueNode) Parent() ValueNode

Parent returns the parent node of this node.

func (*JSONValueNode) SetArrayValueAt

func (vn *JSONValueNode) SetArrayValueAt(index int, value reflect.Value) error

SetArrayValueAt sets this node array element specified at index with new value. User should be careful to not set element with out of bound index. It will return error if its not an array nor slice.

func (*JSONValueNode) SetMapValueAt

func (vn *JSONValueNode) SetMapValueAt(index, newValue reflect.Value) error

SetMapValueAt set the value in this map as specific index/selector value. In json, the index selector must be of type of string.

func (*JSONValueNode) SetObjectValueByField

func (vn *JSONValueNode) SetObjectValueByField(field string, newValue reflect.Value) error

SetObjectValueByField set the value in the node by specified field name.

func (*JSONValueNode) Value

func (vn *JSONValueNode) Value() reflect.Value

Value returns the reflect.Value of this node

type ValueNode

type ValueNode interface {
	IdentifiedAs() string
	Value() reflect.Value
	HasParent() bool
	Parent() ValueNode

	ContinueWithValue(value reflect.Value, identifiedAs string) ValueNode
	GetValue() (reflect.Value, error)
	GetType() (reflect.Type, error)

	IsArray() bool
	GetArrayType() (reflect.Type, error)
	GetArrayValueAt(index int) (reflect.Value, error)
	GetChildNodeByIndex(index int) (ValueNode, error)
	SetArrayValueAt(index int, value reflect.Value) error
	AppendValue(value []reflect.Value) error
	Length() (int, error)

	IsMap() bool
	GetMapValueAt(index reflect.Value) (reflect.Value, error)
	SetMapValueAt(index, newValue reflect.Value) error
	GetChildNodeBySelector(index reflect.Value) (ValueNode, error)

	IsInterface() bool
	IsObject() bool
	GetObjectValueByField(field string) (reflect.Value, error)
	GetObjectTypeByField(field string) (reflect.Type, error)
	SetObjectValueByField(field string, newValue reflect.Value) error
	CallFunction(funcName string, args ...reflect.Value) (reflect.Value, error)
	GetChildNodeByField(field string) (ValueNode, error)

	IsTime() bool
	IsInteger() bool
	IsReal() bool
	IsBool() bool
	IsString() bool
}

ValueNode is an abstraction layer to access underlying dom style data. the node have tree kind of structure which each node are tied to an underlying data node.

func NewGoValueNode

func NewGoValueNode(value reflect.Value, identifiedAs string) ValueNode

NewGoValueNode creates new instance of ValueNode backed by golang reflection

func NewJSONValueNode

func NewJSONValueNode(JSONString, identifiedAs string) (ValueNode, error)

NewJSONValueNode will create a new ValueNode structure backend using data structure as provided by JSON parser.

Jump to

Keyboard shortcuts

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