Documentation ¶
Overview ¶
Package verify uses struct field tags to verify data. There are five tags currently supported:
minSize -- specifies the minimum allowable length of a field. This can only be used on the following types: string, slice, array, or map.
maxSize -- specifies the maximum allowable length of a field. This can only be used on the following types: string, slice, array, or map.
min -- specifies the minimum allowable value of a field. This should only be used on types that can be parsed into an int64 or float64.
max -- specifies the maximum allowable value of a field. This should only be used on types that can be parsed into an int64 or float64.
required -- specifies the field may not be set to the zero value for the given type. This may be used on any types except arrays and structs.
Here is an example of the usage of each tag:
type Foo struct { A []string `verify:"minSize=5"` B string `verify:"maxSize=10"` C int8 `verify:"min=3"` D float32 `verify:"max=1.2"` E int64 `verify:"min=3,max=7"` F *bool `verify:"required"` }
There are currently a few limitation with this project. The first is verify only supports working with flat structures at the moment; it will not work with inner/embedded structs. Also, because the package makes use of reflection the tags may only be used on exported fields.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func It ¶
func It(v interface{}) error
It takes a struct and uses reflection to verify it based on its struct field tags. An error is returned should any of the fields fail their validation. The returned error will describe each field that failed validation. Only interfaces a struct, or a pointer to struct should be passed to this function.
Types ¶
This section is empty.