 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Overview ¶
Data validation library. For introduction, visit https://github.com/gima/govalid/blob/master/README.md
Data type verification ¶
The supplied Validators verify data's type implicitly; they don't need extra parameters during their construction to do so.
// This means, for example, that the following code verifies that "asd" is of
// string type, even though no parameters are given to the String validator.
path, err := govalid.String().Validate("asd")
Supported data types ¶
The supplied validators understand the following data types:
bool, array, map, ptr, slice, string and any numerical type except complex
This leaves out
complex, chan, func, interface, struct and unsafepointer
(Don't be fooled by missing interface{} support, as this library uses reflection to reach values, and reflection goes from interface value to reflection object.)
Regarding pointers ¶
It is recommended to pass pointers to the Validators, as this avoids making copies of data and thus avoids unnecessary garbage collection. Make no mistake, non-pointers work perfectly fine as well.
Index ¶
- type ArrayOpt
- type BooleanOpt
- type NumberOpt
- type ObjectOpt
- type StringOpt
- type Validator
- func And(validators ...Validator) Validator
- func Array(opts ...ArrayOpt) Validator
- func Boolean(opts ...BooleanOpt) Validator
- func Function(validatorfunc ValidatorFunc) Validator
- func Number(opts ...NumberOpt) Validator
- func Object(opts ...ObjectOpt) Validator
- func Optional(validator Validator) Validator
- func Or(validators ...Validator) Validator
- func String(opts ...StringOpt) Validator
 
- type ValidatorFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayOpt ¶
Array validation function. Parameter is reflection to array or slice.
func ArrEach ¶
Array validator function for checking each entry with the specified validator.
func ArrMax ¶
Array validator function for checking maximum number of entries.
type BooleanOpt ¶
Boolean validation function.
type NumberOpt ¶
Number validation function.
func NumMax ¶
Number validator function for checking maximum value.
type ObjectOpt ¶
Object validation function. Parameter is reflection to a map.
func ObjKV ¶
Array validator function for validating a specific key's value (of key->value pair) with the specified validator. If the map under validation doesn't have such key, nil is passed to the Validator (hint: Optional Validator).
keys keys keys
func ObjKeys ¶
Array validator function for validating every key (of key->value pair) with the specified validator.
type StringOpt ¶
String validator function.
func StrIs ¶
String validator function for checking string equality.
func StrMax ¶
String validator function for checking maximum string length.
func StrMin ¶
String validator function for checking minimum string length.
type Validator ¶
type Validator interface {
	// Validate the given data.
	// In the case of a failed validation, path indicates which validator failed.
	Validate(interface{}) (path string, err error)
}
    Validator validates any data type that the implementing validator supports.
func And ¶
Construct a logical-and validator using the specified validators. Given no validators, this validator passes always.
func Array ¶
Construct an array validator using the specified validation functions. Validates data type to be either an array or a slice, or a pointer to such.
func Boolean ¶
func Boolean(opts ...BooleanOpt) Validator
Construct a boolean validator using the specified validation functions. Validates data type to be either a bool or a pointer to such.
func Function ¶
func Function(validatorfunc ValidatorFunc) Validator
Construct a validator using a validation function.
func Number ¶
Construct a number validator using the specified validation functions. Validates data type to be either any numerical type or a pointer to such (except a complex number).
func Object ¶
Construct an object validator using the specified validation functions. Validates data type to be either a map or a pointer to such
Currently this validator supports only map data type.
func Optional ¶
Construct an optional validator using the specified validator. Validation succeeds when given nil or a pointer to nil.
Note: json.Unmarshal() converts JSON null to Go's nil.
func Or ¶
Construct a logical-or validator using the specified validators. Given no validators, this validator passes always.
       Source Files
      ¶
      Source Files
      ¶
    
- and.go
- array.go
- boolean.go
- doc.go
- function.go
- jsonv.go
- number.go
- object.go
- optional.go
- or.go
- string.go