Documentation ¶
Index ¶
- Constants
- type CustomValidation
- type Options
- func (opts *Options) ApplyTransformations(value string) string
- func (opts *Options) Validate(value string, wasProvided, isArrayItem bool) error
- func (opts *Options) ValidateFileContent(file io.ReadSeeker) (mimeType string, err error)
- func (opts *Options) ValidateSlice(values []string, wasProvided bool) error
- type Param
- type Params
- type Scanner
Constants ¶
View Source
const ( // ErrMsgMissingParameter represents the error message corresponding to // a missing param ErrMsgMissingParameter = "parameter missing" // ErrMsgEmptyParameter represents the error message corresponding to // a missing param ErrMsgEmptyParameter = "parameter can be omitted but not empty" // ErrMsgInvalidUUID represents the error message corresponding to // an invalid UUID ErrMsgInvalidUUID = "not a valid uuid" // ErrMsgInvalidSlug represents the error message corresponding to // an invalid slug ErrMsgInvalidSlug = "not a valid slug" // ErrMsgInvalidSlugOrUUID represents the error message corresponding to // a field that is neither a slug or a UUIDv4 ErrMsgInvalidSlugOrUUID = "not a valid slug" // ErrMsgInvalidURL represents the error message corresponding to // an invalid URL ErrMsgInvalidURL = "not a valid url" // ErrMsgInvalidEmail represents the error message corresponding to // an invalid Email address ErrMsgInvalidEmail = "not a valid email" // ErrMsgInvalidImage represents the error message corresponding to // an invalid image ErrMsgInvalidImage = "not a valid image" // ErrMsgMaxLen represents the error message corresponding to // a field that exceed the maximum number of char ErrMsgMaxLen = "too many chars" // ErrMsgEnum represents the error message corresponding to // a field that doesn't contain a value set in an enum ErrMsgEnum = "not a valid value" // ErrMsgInvalidBoolean represents the error message corresponding to // an invalid boolean ErrMsgInvalidBoolean = "invalid boolean" // ErrMsgInvalidInteger represents the error message corresponding to // an invalid integer ErrMsgInvalidInteger = "invalid integer" // ErrMsgIntegerTooBig represents the error message corresponding to // an integer being too big ErrMsgIntegerTooBig = "value too high" // ErrMsgIntegerTooSmall represents the error message corresponding to // an integer being too small ErrMsgIntegerTooSmall = "value too small" // ErrMsgEmptyFile represents the error message corresponding to // an empty file being sent ErrMsgEmptyFile = "file empty" // ErrMsgCorruptedFile represents the error message corresponding to // a corrupted file ErrMsgCorruptedFile = "file seems corrupted" // ErrMsgArrayTooBig represents the error message corresponding to // an array being too big ErrMsgArrayTooBig = "too many elements" // ErrMsgArrayTooSmall represents the error message corresponding to // an array being too small ErrMsgArrayTooSmall = "too few elements" // ErrMsgEmptyItem represents the error message corresponding to // an array containing an empty item ErrMsgEmptyItem = "array cannot contain empty items" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CustomValidation ¶
type CustomValidation interface { // IsValid checks if the provided params are valid. // returns a boolean, the name of the field that failed (if any), // and the error (if any) IsValid() (isValid bool, fieldFailing string, err error) }
CustomValidation is an interface used to implements custom validation on a structure
type Options ¶
type Options struct { // AuthorizedValues represents the list of authorized value for this param // enum:"and,or" AuthorizedValues []string // MinInt represents the minimum value accepted for an integer // min_int:"1" MinInt *int // MaxInt represents the maximum value accepted for an integer // max_int:"255" MaxInt *int // MaxItems represents the maximum number of values accepted by an array // max_items:"10" MaxItems *int // MinItems represents the minimum number of values accepted by an array // min_items:"10" MinItems *int // MaxLen represents the maximum length a param can have (under its string // form). Any invalid values (including 0) will be ignored // maxlen:"255" MaxLen int // Name contains the name of the field in the payload // json:"my_field" Name string // Ignore means the field should not been parsed // json:"-" Ignore bool // Required means the request should fail with a Bad Request if the field is missing. // params:"required" Required bool // Trim means the field needs to be trimmed before being retrieved and checked // params:"trim" Trim bool // ValidateUUID means the field should contain a valid UUIDv4 // params:"uuid" ValidateUUID bool // ValidateSlug means the field should contain a valid slug // params:"slug" ValidateSlug bool // ValidateSlugOrUUID means the field should contain a valid slug or a valid // UUIDv4 // params:"slugOrUuid" ValidateSlugOrUUID bool // ValidateEmail means the field should contain a valid email // params:"email" ValidateEmail bool // ValidateURL means the field should contain a valid url // params:"url" ValidateURL bool // ValidateImage means the field should contain a valid image // params:"image" ValidateImage bool // NoEmpty means the field should not contain an empty value // The difference between `required` and `noempty` is that `require` does` // not accept nil pointer. `noempty` accepts nil pointer, but if a value is // provided it cannot be an empty string. // params:"noempty" NoEmpty bool // NoEmptyItems means all items of an array needs to have a value //params:"no_empty_items" NoEmptyItems bool }
Options represent all the options for a field
func NewOptions ¶
NewOptions returns a ParamOptions from a StructTag
func (*Options) ApplyTransformations ¶
ApplyTransformations applies all the wanted transformations to the given value
func (*Options) ValidateFileContent ¶
func (opts *Options) ValidateFileContent(file io.ReadSeeker) (mimeType string, err error)
ValidateFileContent checks the given file passes the options set
type Param ¶
Param represents a struct param
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
mockformfile
Package mockformfile is a generated GoMock package.
|
Package mockformfile is a generated GoMock package. |
Click to show internal directories.
Click to hide internal directories.