Documentation ¶
Index ¶
- Variables
- func Validate(obj interface{}, field string, args ...interface{}) error
- func ValidationFunction(obj interface{}, field string, args ...interface{}) (fn reflect.Value, err error)
- type Configurator
- type Struct
- type Tag
- func (t *Tag) Alphanumeric() bool
- func (t *Tag) CodecName() string
- func (t *Tag) Has(opt string) bool
- func (t *Tag) IntValue(key string) (int, bool)
- func (t *Tag) IsEmpty() bool
- func (t *Tag) Length() (int, bool)
- func (t *Tag) MaxLength() (int, bool)
- func (t *Tag) MinLength() (int, bool)
- func (t *Tag) Name() string
- func (t *Tag) Optional() bool
- func (t *Tag) PipeName() string
- func (t *Tag) Required() bool
- func (t *Tag) Value(key string) string
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoStruct = errors.New("not an struct") ErrNoFields = errors.New("struct has no fields") )
Functions ¶
func Validate ¶
Validate calls the validation function in obj for the given field, if any. Given a field F, its validation function must be called ValidateF. It might be either a method or a field named like that. If both exist, the method takes precedence. Validation functions must return a single argument of type error. As for the input parameters of the validation function, their types must match the types of the args parameter. However, validation functions are allowed to have a different number of arguments than the amount provided in args. If the validation function takes less arguments any additional arguments are ignored. On the other hand, if the validation function receives more arguments that len(args), they will be zero for the corresponding type (as returned by reflect.Zero).
Validate returns an error in the following three cases:
- The function exists, but its return type is not error (or has a number of return values != 1).
- The function exists, but its arguments don't match the types in args.
- The function exists and when executed returns an error != nil.
func ValidationFunction ¶
func ValidationFunction(obj interface{}, field string, args ...interface{}) (fn reflect.Value, err error)
ValidationFunction returns the validation function in obj to validate the field argument with the given arguments. See the documentation on Validate to learn more about validation functions.
Types ¶
type Configurator ¶
type Struct ¶
type Struct struct { // The Struct type Type reflect.Type // Lists the mangled names of the fields, in order MNames []string // List the names of the qualified struct fields (e.g. Foo.Bar) in order QNames []string // Lists the indexes of the members (for FieldByIndex()) Indexes [][]int // Field types, in order Types []reflect.Type // Field tags, in order Tags []*Tag // Maps mangled names to indexes MNameMap map[string]int // Maps qualified names to indexes QNameMap map[string]int // Lists the field indexes prefix for pointers in embedded structs Pointers [][]int // contains filtered or unexported fields }
type Tag ¶
type Tag struct {
// contains filtered or unexported fields
}
func MustParseTag ¶
MustParseTag works like ParseTag, but panics if there's an error.
func NewStringTagNamed ¶
func NewTagNamed ¶
func NewTagNamed(field reflect.StructField, name string) *Tag