Documentation
¶
Overview ¶
Code generated by genx:code DO NOT EDIT.
Code generated by genx:enum DO NOT EDIT.
Index ¶
- Constants
- Variables
- func IsNil(n Node) bool
- func SingleQuote(data []byte) []byte
- func Slash(data []byte) []byte
- type Builder
- type Error
- type Literal
- type Matcher
- type Matrix
- type Node
- type NodeType
- func (v NodeType) IsZero() bool
- func (v NodeType) MarshalText() ([]byte, error)
- func (v *NodeType) Scan(src any) error
- func (v NodeType) String() string
- func (v NodeType) Text() string
- func (t NodeType) Type() NodeType
- func (v *NodeType) UnmarshalText(data []byte) error
- func (v NodeType) Value() (driver.Value, error)
- func (NodeType) Values() []NodeType
- type Parameter
- type Ranges
- type Requirements
- type Rule
Constants ¶
View Source
const ( TOK_LEADER rune = '@' TOK_OPTIONAL rune = '?' TOK_EQUAL rune = '=' TOK_RANGE_IN_L rune = '[' TOK_RANGE_IN_R rune = ']' TOK_RANGE_EX_L rune = '(' TOK_RANGE_EX_R rune = ')' TOK_VALUES_L rune = '{' TOK_VALUES_R rune = '}' TOK_PARAM_L rune = '<' TOK_PARAM_R rune = '>' TOK_REGEXP rune = '/' TOK_SPLITTER rune = ',' )
Variables ¶
View Source
var KeyTokens = map[rune]struct{}{ TOK_LEADER: {}, TOK_OPTIONAL: {}, TOK_EQUAL: {}, TOK_RANGE_IN_L: {}, TOK_RANGE_IN_R: {}, TOK_RANGE_EX_L: {}, TOK_RANGE_EX_R: {}, TOK_VALUES_L: {}, TOK_VALUES_R: {}, TOK_PARAM_L: {}, TOK_PARAM_R: {}, TOK_REGEXP: {}, TOK_SPLITTER: {}, }
Functions ¶
func SingleQuote ¶
Types ¶
type Builder ¶
type Error ¶
type Error int8
Error defines error code for validation rule +genx:code
const ( ERROR_UNDEFINED Error = iota ERROR__INVALID_RULE_LEADER // invalid rule name leader, expect start with '@' ERROR__MISSING_RULE_NAME // missing rule name ERROR__INVALID_PARAM_LEADER // invalid rule parameter list leader, expect start with '<' ERROR__INVALID_PARAM_TAILER // invalid rule parameter list tailer, expect end with '>' ERROR__INVALID_PARAMS // invalid rule parameter list content ERROR__INVALID_RANGE_LEADER // invalid rule range leader, expect start with '[' or '(' ERROR__INVALID_RANGE_TAILER // invalid rule range tailer, expect end with ']' or ')' ERROR__INVALID_RANGE_COUNT // invalid rule range count, expect 1 or 2 ERROR__INVALID_RANGE_MODE // invalid rule range mode, while length mode must be quoted with '[]' ERROR__INVALID_VALUE_LEADER // invalid rule value leader, expect start with '{' ERROR__INVALID_VALUE_TAILER // invalid rule value tailer, expect end with '}' ERROR__INVALID_REGEXP_LEADER // invalid rule matcher leader, expect start with '/' ERROR__INVALID_REGEXP_TAILER // invalid rule matcher leader, expect end with '/' ERROR__FAILED_COMPILE_REGEXP // failed to compile regexp ERROR__INVALID_QUOTED_DEFAULT_TAILER // invalid rule quoted default value tailer, expect quoted with `'` ERROR__INVALID_LITERAL // invalid rule literal )
type Literal ¶
type Literal struct {
NodeType
// contains filtered or unexported fields
}
func NewLiteral ¶
type Matcher ¶
type Matcher interface {
Node
// Pattern returns regexp literal
// eg: @string='s'/\w+/ => string value must match \w+
Pattern() string
SetPattern(string) error
// Regexp returns compiled regexp
Regexp() *regexp.Regexp
}
func NewMatcher ¶
func NewMatcher() Matcher
type Matrix ¶
type NodeType ¶
type NodeType int8
NodeType rule node type +genx:enum
func ParseNodeType ¶
ParseNodeType parse NodeType from key
func (NodeType) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (*NodeType) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler
type Parameter ¶
type Parameter interface {
Node
// Parameters returns parameter of rule
// eg:
// @map<@string,@int?> => map value with string key and int value
// @string<byte>[10] => string value with max 10 byte length
// @string<rune>[10] => string value with max 10 rune length
// @slice<@float64<10,4>[-1000.0001,1000.0002]> => slice with float64 with width 10 and precision 4 and between -1000.0001 and 1000.0002
Parameters() []Node
AddParameters(...Node)
}
func NewParameters ¶
func NewParameters() Parameter
type Ranges ¶
type Ranges interface {
Node
Min() (*Literal, bool)
SetMin(*Literal, bool)
Max() (*Literal, bool)
SetMax(*Literal, bool)
LengthMode() bool
SetLengthMode(bool)
}
Ranges describes validation value's range eg:
@int32[,10] => int32 value must greater than or equal to 0 and less than or equal to 10 @int64(,10) => int64 value must greater than 0 and less or equal than 10 @string[10,) => string length must greater than or equal to 10 @string[10] => string length must equal to 10
type Requirements ¶
type Requirements interface {
Node
// Optional returns if field is optional
// eg: @string? => optional string value
Optional() bool
SetOptional(bool)
// Defaults returns default value of field
// eg: @string='abc' => string value defaults is "abc" if not assigned
Defaults() *Literal
SetDefaults(*Literal)
}
func NewRequirements ¶
func NewRequirements() Requirements
type Rule ¶
type Rule interface {
Node
// Name returns name of rule
Name() string
// Parameters returns parameter of rule
// eg:
// @map<@string,@int?> => map value with string key and int value
// @string<byte>[10] => string value with max 10 byte length
// @string<rune>[10] => string value with max 10 rune length
// @slice<@float64<10,4>[-1000.0001,1000.0002]> => slice with float64 with width 10 and precision 4 and between -1000.0001 and 1000.0002
Parameters() []Node
// Min returns range minimum value and exclusive
// eg: @int(0,10) => min: 0 exclusive: true
Min() (*Literal, bool)
// Max returns range maximum value and exclusive
// eg: @int(0,10] => max: 10 exclusive: false
Max() (*Literal, bool)
// LengthMode return if range use LengthMode
// eg: @string[10] => length of string must be 10
LengthMode() bool
// ValueMatrix returns value's enumeration value matrix
// eg:
// @string{A,B,C} value must be A, B or C
// @slice<@int>{1,2,3}{4,5,6} slice value must be []int{1,2,3} or []int{4,5,6}
ValueMatrix() [][]*Literal
// Pattern returns regexp literal
// eg: @string='s'/\w+/ => string value must match \w+
Pattern() string
// Regexp returns compiled regexp
Regexp() *regexp.Regexp
// Optional returns if field is optional
// eg: @string? => optional string value
Optional() bool
// Defaults returns default value of field
// eg: @string='abc' => string value defaults is "abc" if not assigned
Defaults() *Literal
}
func MustCompile ¶
Click to show internal directories.
Click to hide internal directories.