model

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: Apache-2.0 Imports: 10 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ValidConditionTypes = map[ConditionType]int{
	NONE:         0,
	EQUAL:        1,
	NOT_EQUAL:    2,
	MIN_VALUE:    3,
	MAX_VLAUE:    4,
	CONTAINS:     5,
	NOT_CONTAINS: 6,
	FROM:         7,
	NOT_FROM:     8,
	REGX:         9,
}

Functions

func GetArrayFromCondition

func GetArrayFromCondition(condition string) ([]string, error)

func GetConditionByType

func GetConditionByType(conditionFull string, conditionType ConditionType) (string, error)

func GetConditionsAndOrFromString

func GetConditionsAndOrFromString(in string) ([]string, bool)

func ISO8601StringToTime added in v0.2.1

func ISO8601StringToTime(in string) (time.Time, error)

func InterfaceFromFloat added in v0.2.1

func InterfaceFromFloat(in float64, inType ValidatorType) (interface{}, error)

func InterfaceFromInt added in v0.2.1

func InterfaceFromInt(in int, inType ValidatorType) (interface{}, error)

func InterfaceFromString added in v0.1.9

func InterfaceFromString(in string, inType ValidatorType) (interface{}, error)

func LookupConditionType added in v0.2.0

func LookupConditionType(conType ConditionType) error

LookupConditionType checks our validConditionType map for the scanned condition type. If not found, an error is returned.

func LookupOperator added in v0.2.0

func LookupOperator(operator Operator) error

LookupOperator checks our validOperator map for the scanned operator. If not found, an error is returned.

func UnixStringToTime added in v0.2.1

func UnixStringToTime(in string) (time.Time, error)

Types

type AstValue added in v0.2.0

type AstValue struct {
	Type           AstValueType
	ConditionType  ConditionType
	ConditionValue string
	ConditionGroup ConditionGroup
	Operator       Operator
	Start          int
	End            int
}

AstValue holds a Type ("Condition" or "Group") as well as a `ConditionType` and `ConditionValue`. The ConditionType is a model.ConditionType and the ConditionValue is any string (numbers are also represented as string).

func (AstValue) AstConditionToString added in v0.2.0

func (r AstValue) AstConditionToString() string

func (AstValue) AstGroupToString added in v0.2.0

func (r AstValue) AstGroupToString() string

func (AstValue) RunFuncOnConditionGroup added in v0.2.0

func (r AstValue) RunFuncOnConditionGroup(input reflect.Value, f func(reflect.Value, *AstValue) error) error

type AstValueType added in v0.2.0

type AstValueType string
const (
	EMPTY     AstValueType = "Empty"
	GROUP     AstValueType = "Group"
	CONDITION AstValueType = "Condition"
)

type ConditionGroup added in v0.2.0

type ConditionGroup []*AstValue

type ConditionType added in v0.2.0

type ConditionType string

ConditionType is the type for all available condition types.

const (
	NONE         ConditionType = "-"
	EQUAL        ConditionType = "equ"
	NOT_EQUAL    ConditionType = "neq"
	MIN_VALUE    ConditionType = "min"
	MAX_VLAUE    ConditionType = "max"
	CONTAINS     ConditionType = "con"
	NOT_CONTAINS ConditionType = "nco"
	FROM         ConditionType = "frm"
	NOT_FROM     ConditionType = "nfr"
	REGX         ConditionType = "rex"
)

Available condition types.

func GetConditionType

func GetConditionType(s string) (ConditionType, error)

type Group added in v0.2.1

type Group struct {
	Name           string
	ConditionType  ConditionType
	ConditionValue string
}

func GetGroups added in v0.2.1

func GetGroups(s string) ([]*Group, error)

type JsonMap

type JsonMap map[string]interface{}

func (*JsonMap) Has added in v0.1.9

func (r *JsonMap) Has(key string) bool

func (JsonMap) Marshal

func (r JsonMap) Marshal() ([]byte, error)

func (*JsonMap) Scan

func (c *JsonMap) Scan(value interface{}) error

func (*JsonMap) Unmarshal

func (r *JsonMap) Unmarshal(value interface{}) error

func (JsonMap) Value

func (c JsonMap) Value() (driver.Value, error)

type Operator added in v0.2.0

type Operator string

Operator is the type for all available operators.

const (
	// Group states
	AND Operator = "&&"
	OR  Operator = "||"
)

Available operators.

type RootNode added in v0.2.0

type RootNode struct {
	RootValue *AstValue
}

RootNode is what starts every parsed AST.

type TagType added in v0.2.1

type TagType string
const (
	VLD TagType = "vld"
	UPD TagType = "upd"
)

type Token added in v0.2.0

type Token struct {
	Type    TokenType
	Literal string
	Line    int
	Start   int
	End     int
}

type TokenType added in v0.2.0

type TokenType string
const (
	// Token/character we don't know about
	LexerIllegal TokenType = "ILLEGAL"

	// Empty condition
	LexerEmptyRequirement TokenType = "EMPTY"

	// End of file
	LexerEOF TokenType = "EOF"

	// Group
	LexerLeftBrace  TokenType = "GROUP_OPEN"
	LexerRightBrace TokenType = "GROUP_CLOSE"

	// Literals
	LexerConditionType        TokenType = "CONDITION_TYPE"
	LexerConditionValue       TokenType = "CONDITION_VALUE"
	LexerConditionValueString TokenType = "CONDITION_VALUE_STRING"

	// Operators
	LexerOperator TokenType = "OPERATOR"
)

type Validation

type Validation struct {
	Key         string
	Type        ValidatorType
	Requirement string
	Groups      []*Group
}

func (*Validation) Fill added in v0.2.1

func (r *Validation) Fill(tag string, tagType TagType, value reflect.Value) error

func (*Validation) FillOnlyKey added in v0.2.8

func (r *Validation) FillOnlyKey(tag string, tagType TagType, value reflect.Value) error

func (*Validation) GetValidValue added in v0.2.1

func (r *Validation) GetValidValue(in interface{}) (interface{}, error)

type ValidatorMap

type ValidatorMap map[string]Validation

type ValidatorType

type ValidatorType string
const (
	String      ValidatorType = "string"
	Int         ValidatorType = "int"
	Float       ValidatorType = "float"
	Bool        ValidatorType = "bool"
	Array       ValidatorType = "array"
	Map         ValidatorType = "map"
	Struct      ValidatorType = "struct"
	Time        ValidatorType = "time"
	TimeISO8601 ValidatorType = "timeIso8601"
	TimeUnix    ValidatorType = "timeUnix"
)

func TypeFromInterface added in v0.1.9

func TypeFromInterface(in interface{}) ValidatorType

Jump to

Keyboard shortcuts

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