Documentation
¶
Index ¶
- type Validator
- func (this *Validator) Bool(path string) (val bool, err error)
- func (this *Validator) BoolSlice(path string) (val []bool, err error)
- func (this *Validator) Float(path string) (val float64, err error)
- func (this *Validator) FloatSlice(path string) (val []float64, err error)
- func (this *Validator) Int(path string) (val int, err error)
- func (this *Validator) Int64(path string) (val int64, err error)
- func (this *Validator) Int64Slice(path string) (val []int64, err error)
- func (this *Validator) IntSlice(path string) (val []int, err error)
- func (this *Validator) JsonObj() jsonIter.Any
- func (this *Validator) String(path string) (val string, err error)
- func (this *Validator) StringObjectMap(path string) (val mapUtil.StringObjectMap, err error)
- func (this *Validator) StringSlice(path string) (val []string, err error)
- func (this *Validator) Validate(path string, operator comparer.Operator, val interface{}, option int) (bool, error)
- func (this *Validator) Value(path string) (val interface{}, err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
func New ¶
func New(data interface{}) *Validator
创建一个表达式验证器。
Example ¶
obj := New(`
{
"code": 1,
"message": "test",
"data": {
"userId": 1,
"user": {"id": 1, "name": "test"},
"id": [1,2,3],
"items": [
{"id": 1, "name": "a"},
{"id": 2, "name": "b"},
{"id": 3, "name": "c"},
{"id": 4, "name": "d"},
{"id": 5, "name": "e"}
]
}
}`)
// float64(1)
val, _ := obj.Value("code")
// int(1)
nVal, _ := obj.Int("code")
// string("test")
val, _ = obj.Value("message")
// map[string]interface{}{...}
val, _ = obj.Value("data")
// map[string]interface{}{"id": 1, "name": "test"}
val, _ = obj.Value("data.user")
// []int64{1,2,3}
val, _ = obj.Value("data.id")
// []int{1,2,3}
arrVal, _ := obj.IntSlice("data.id")
// int64(2)
val, _ = obj.Value("data.id.1")
// []int64{1,2,3,4,5}
val, _ = obj.Value("data.items.*.id")
// []string{"a","b","c","d","e"}
val, _ = obj.Value("data.items.*.name")
print(val, nVal, arrVal)
func (*Validator) FloatSlice ¶
func (*Validator) Int64Slice ¶
func (*Validator) StringObjectMap ¶
func (this *Validator) StringObjectMap(path string) (val mapUtil.StringObjectMap, err error)
func (*Validator) StringSlice ¶
Click to show internal directories.
Click to hide internal directories.