Documentation ¶
Index ¶
Constants ¶
const ( // Any is the default type value. This means the Validator will accept any // object type and just confirms it exists. Any kind = iota // None is the opposite of the Any type. This will instruct the validator to // ensure the value is null // or non-existent. None // Number represents a type of integer or float value. These are stored as // float64 values. Number // Int represents a type of integer value. Similar to having the Rule 'Integer'. Int // String represents a string type value. String // Bool is a type that is either true or false. Bool // Object is a type that can be used to ensure the result is a complex map or // non-list type. Object // List is a type that will represent a generic list/array/slice input. List // ListNumber is a type that goes further than List and ensures that all the // list entries are valid numbers. ListNumber // ListString is a type that goes further than List and ensures that all the // list entries are valid strings. ListString )
const ( // Float adds a number constraint to ensure a number does contain a decimal // or a decimal of greater than zero. Float = number(false) // Integer adds a number constraint to ensure a number does not contain a // decimal or a decimal of zero. Integer = number(true) // Positive adds a number constraint to ensure a number is zero or greater. Positive = polarity(true) // Negative adds a number constraint to ensure a number is less than zero. Negative = polarity(false) // GreaterThanZero adds a number constraint to ensure a number greater than //zero. GreaterThanZero = Min(1) )
Variables ¶
var ErrInvalidName = errors.New("invalid name in set")
ErrInvalidName is a validation error returned when a Validator rule has an empty name.
var ID = Rules{Integer, GreaterThanZero}
ID is a ruleset that allows for identifying an ID value.
var ( // NoEmpty adds a string constraint to ensure a string value cannot be empty. NoEmpty = &Length{Min: 1} )
Functions ¶
This section is empty.
Types ¶
type Length ¶
type Length struct {
Min, Max uint64
}
Length adds a string or array length constraint to be used. Max value is ignored if empty or less than Min.
type Rule ¶
Rule is an interface that can be used to assist with verifying the correct data passed to the Validator.
The 'Validate' function will be passed the object in question and should return nil if it passes.
func Contains ¶
Contains returns a Rule that will verify that the value is a string and contains the supplied string.
func MustRegex ¶
MustRegex will return a regular expression validator. This function will panic f the expression has any errors compiling.
func Prefix ¶
Prefix returns a Rule that will verify that the value is a string and starts with the supplied string.
type Rules ¶
type Rules []Rule
Rules is an alias for a list of Rules that can be used to validate Content constraints.
type Set ¶
type Set []Validator
Set is an alias for a list of Validators that can be used to validate a request data body.
func (Set) Validate ¶
Validate will check the rules of this Set against the supplied content object. This function will return nil if the Content is considered valid.
func (Set) ValidateEmpty ¶
ValidateEmpty will check the rules of this Set against the supplied content object.
This function will return nil if the Content is considered valid or if the Content is empty. This function allows for specifying and validating optional data.
type SubSet ¶
type SubSet Set
SubSet is a type if Set that can be used to validate a complex object that is a child of an object being validated.
SubSets have the same options as a Set.
type Validator ¶
type Validator struct { Name string `json:"name"` Rules Rules `json:"rules"` Type kind `json:"type"` Optional bool `json:"optional,omitempty"` }
Validator is a struct used to assist with data body validation. This struct can be used inside a Set to add rules for incoming data.
The Rules attribute can be used to add more constraints on the Validator.