5 // FieldLevel contains all the information and helper functions
7 type FieldLevel interface {
9 // returns the top level struct, if any
12 // returns the current fields parent struct, if any or
13 // the comparison value if called 'VarWithValue'
14 Parent() reflect.Value
16 // returns current field for validation
19 // returns the field's name with the tag
20 // name takeing precedence over the fields actual name.
23 // returns the struct field's name
24 StructFieldName() string
26 // returns param for validation against current field
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)
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
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)
43 var _ FieldLevel = new(validate)
45 // Field returns current field for validation
46 func (v *validate) Field() reflect.Value {
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 {
56 // StructFieldName returns the struct field's name
57 func (v *validate) StructFieldName() string {
61 // Param returns param for validation against current field
62 func (v *validate) Param() string {
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)