OSDN Git Service

new repo
[bytom/vapor.git] / vendor / gopkg.in / go-playground / validator.v9 / field_level.go
1 package validator
2
3 import "reflect"
4
5 // FieldLevel contains all the information and helper functions
6 // to validate a field
7 type FieldLevel interface {
8
9         // returns the top level struct, if any
10         Top() reflect.Value
11
12         // returns the current fields parent struct, if any or
13         // the comparison value if called 'VarWithValue'
14         Parent() reflect.Value
15
16         // returns current field for validation
17         Field() reflect.Value
18
19         // returns the field's name with the tag
20         // name takeing precedence over the fields actual name.
21         FieldName() string
22
23         // returns the struct field's name
24         StructFieldName() string
25
26         // returns param for validation against current field
27         Param() string
28
29         // ExtractType gets the actual underlying type of field value.
30         // It will dive into pointers, customTypes and return you the
31         // underlying value and it's kind.
32         ExtractType(field reflect.Value) (value reflect.Value, kind reflect.Kind, nullable bool)
33
34         // traverses the parent struct to retrieve a specific field denoted by the provided namespace
35         // in the param and returns the field, field kind and whether is was successful in retrieving
36         // the field at all.
37         //
38         // NOTE: when not successful ok will be false, this can happen when a nested struct is nil and so the field
39         // could not be retrieved because it didn't exist.
40         GetStructFieldOK() (reflect.Value, reflect.Kind, bool)
41 }
42
43 var _ FieldLevel = new(validate)
44
45 // Field returns current field for validation
46 func (v *validate) Field() reflect.Value {
47         return v.flField
48 }
49
50 // FieldName returns the field's name with the tag
51 // name takeing precedence over the fields actual name.
52 func (v *validate) FieldName() string {
53         return v.cf.altName
54 }
55
56 // StructFieldName returns the struct field's name
57 func (v *validate) StructFieldName() string {
58         return v.cf.name
59 }
60
61 // Param returns param for validation against current field
62 func (v *validate) Param() string {
63         return v.ct.param
64 }
65
66 // GetStructFieldOK returns Param returns param for validation against current field
67 func (v *validate) GetStructFieldOK() (reflect.Value, reflect.Kind, bool) {
68         return v.getStructFieldOKInternal(v.slflParent, v.ct.param)
69 }