Documentation ¶
Overview ¶
Package validation contains configurations for validating payload and path variable input.
Index ¶
- Constants
- func CountriesISO2() map[string]*Country
- func CountriesISO3() map[string]*Country
- func Hash256(input string) string
- func IsAlpha(s string) (bool, string)
- func IsAlphanumeric(s string) (bool, string)
- func Languages() map[string]*Language
- func ReverseCountries() map[string]*Country
- func Sanitize(s string) string
- type Array
- type BodyValidationFunction
- type Config
- func ArrayFloat64() *Config
- func ArrayInt() *Config
- func ArrayInterface() *Config
- func ArrayString() *Config
- func Base64Decode() *Config
- func Bool() *Config
- func CountryISO2() *Config
- func CountryISO3() *Config
- func EmailAddress() *Config
- func EmailAddressOptional() *Config
- func Float64(ranges ...int) *Config
- func Hex(min, max float64) *Config
- func HexDecode(min, max float64) *Config
- func HexSHA1() *Config
- func HexSHA256() *Config
- func IPv4Address() *Config
- func Int() *Config
- func Int64() *Config
- func IntOptimistic() *Config
- func IntPessimistic() *Config
- func Interface() *Config
- func Json() *Config
- func LanguageISO2() *Config
- func MapStringInterface() *Config
- func NegativeInt() *Config
- func NewConfig(validationType interface{}, pathFunction PathValidationFunction, ...) *Config
- func Now() *Config
- func PasswordHard() *Config
- func PasswordWeak() *Config
- func PhoneNumber(countryCode string) *Config
- func PositiveInt() *Config
- func SQLTimestamp() *Config
- func Slice(vc *Config) *Config
- func String(min, max float64) *Config
- func StringExact(max float64) *Config
- func StringSet(set ...string) *Config
- func StringSplit(delimiter string) *Config
- func Time(layout string) *Config
- func URL() *Config
- func UUIDv4() *Config
- func Username(min, max float64) *Config
- type Country
- type IPv4
- type JSON
- type Language
- type Object
- type Optional
- type Patch
- type PathValidationFunction
- type Payload
- type Spec
Constants ¶
const ( STRING_MAX_LENGTH = 2000.0 PASSWORD_MIN_LENGTH = 8.0 ALPHABET = "abcdefghijklmnopqrstuvwxyz" NUMERIC = "0123456789" USERNAME_CHARS = ALPHABET + "_" + NUMERIC // mocking CONST_MOCK_EMAIL = "user@examplemail.com" )
const ( ERR_INVALID_CHARS = "PARAM CONTENTS INVALID" ERR_RANGE_EXCEED = "PARAM VALUE IS OUT OF RANGE BOUNDS" ERR_RANGE_NAN = "PARAM VALUE IS NaN" ERR_NOT_OBJECT = "PARAM IS NOT AN OBJECT" ERR_NOT_ARRAY = "PARAM IS NOT AN ARRAY" ERR_NOT_STRING = "PARAM IS NOT A STRING" ERR_NOT_INT = "PARAM IS NOT AN INT" ERR_NOT_INT64 = "PARAM IS NOT AN INT64" ERR_NOT_FLOAT64 = "PARAM IS NOT A FLOAT64" ERR_NOT_BOOL = "PARAM IS NOT A BOOLEAN" ERR_PARSE_INT64 = "PARAM FAILED TO PARSE AS INT64" ERR_PARSE_FLOAT64 = "PARAM FAILED TO PARSE AS FLOAT64" ERR_PARSE_TIME = "PARAM FAILED TO PARSE AS TIME" ERR_PARSE_URL = "PARAM FAILED TO PARSE AS URL" )
const (
COUNTRY_CSV = `` /* 21763-byte string literal not displayed */
)
Variables ¶
This section is empty.
Functions ¶
func CountriesISO2 ¶
CountriesISO2 returns the map of alpha-2 codes to country structs.
func CountriesISO3 ¶
CountriesISO3 returns the map of alpha-3 codes to country structs.
func Hash256 ¶
Hash256 is a tool to exec the SHA25 on strings, taking a string input, and outputting hex.
func IsAlphanumeric ¶
IsAlphanumeric checks if a string is alphanumeric.
func ReverseCountries ¶
ReverseCountries maps the country names to the country structs.
Types ¶
type BodyValidationFunction ¶
type Config ¶
type Config struct { Model interface{} `json:"model"` Type string `json:"type"` PathFunction PathValidationFunction `json:"-"` BodyFunction BodyValidationFunction `json:"-"` Keys []string `json:"-"` Min float64 `json:"min"` Max float64 `json:"max"` RequiredValue bool `json:"required"` SummaryValue string `json:"summary"` DefaultValue interface{} `json:"default"` DescriptionValue string `json:"description"` }
func ArrayFloat64 ¶
func ArrayFloat64() *Config
ArrayFloat64 returns a validation object that checks for a slice of float64
func ArrayInt ¶
func ArrayInt() *Config
ArrayInt returns a validation object that checks for a slice of integers
func ArrayInterface ¶
func ArrayInterface() *Config
ArrayInterface returns a validation object for request body that checks a property to see if it's an array
func ArrayString ¶
func ArrayString() *Config
ArrayString returns a validation object that allows any value
func Base64Decode ¶
func Base64Decode() *Config
Base64Decode returns a validation object which checks for valid username
func Bool ¶
func Bool() *Config
Bool returns a validation object that checks for a bool which parses correctly
func CountryISO2 ¶
func CountryISO2() *Config
CountryISO2 returns a validation object that checks to see if it can resolve to a country struct
func CountryISO3 ¶
func CountryISO3() *Config
CountryISO3 returns a validation object that checks to see if it can resolve to a country struct
func EmailAddress ¶
func EmailAddress() *Config
EmailAddress returns a validation object which checks for valid email address
func EmailAddressOptional ¶
func EmailAddressOptional() *Config
Returns a validation object which checks for valid email address
func Hex ¶
Hex returns a validation object that checks for a hex string with a length within optional range
func HexDecode ¶
Returns a validation object that decodes a hex string with a length within optional range
func HexSHA1 ¶
func HexSHA1() *Config
Returns a validation object that checks for a hex string with length of 40 chars.
func HexSHA256 ¶
func HexSHA256() *Config
Returns a validation object that checks for a hex string with length of 64 chars.
func IPv4Address ¶
func IPv4Address() *Config
IPv4Address returns a validation object that checks for a string with a length within optional range
func Int ¶
func Int() *Config
Int returns a validation object that checks for an int which parses correctly
func Int64 ¶
func Int64() *Config
Int64 returns a validation object that checks for an int64 which parses correctly
func IntOptimistic ¶
func IntOptimistic() *Config
Returns a validation object that checks for an int which parses correctly and is zero or above
func IntPessimistic ¶
func IntPessimistic() *Config
Returns a validation object that checks for an int which parses correctly and is zero or lower
func Interface ¶
func Interface() *Config
Interface returns a validation object that allows any value
func LanguageISO2 ¶
func LanguageISO2() *Config
LanguageISO2 returns a validation object that checks to see if it can resolve to a country struct
func MapStringInterface ¶
func MapStringInterface() *Config
MapStringInterface returns a validation object for request body that checks a property to see if it's an object
func NegativeInt ¶
func NegativeInt() *Config
Returns a validation object that checks for an int which parses correctly and is negative
func NewConfig ¶
func NewConfig(validationType interface{}, pathFunction PathValidationFunction, bodyFunction BodyValidationFunction, ranges ...float64) *Config
NewConfig creates a new validation config with the supplied parameters.
func PasswordHard ¶
func PasswordHard() *Config
Returns a validation object which checks for password
func PasswordWeak ¶
func PasswordWeak() *Config
PasswordWeak returns a validation object which checks for password
func PhoneNumber ¶
PhoneNumber returns a validation object that checks to see if a valid phone number is provided
func PositiveInt ¶
func PositiveInt() *Config
Returns a validation object that checks for an int which parses correctly and is positive
func SQLTimestamp ¶
func SQLTimestamp() *Config
SQLTimestamp returns a validation object which checks for valid time
func String ¶
String returns a validation object that checks for a string with a length within optional range
func StringExact ¶
StringExact returns a validation object that checks for a string with exact length
func StringSplit ¶
StringSplit returns a validation object which checks for delimiter-separated string like CSV
func Time ¶
Time returns a validation object which checks for valid time like 2017-06-23T00:00:00.000Z
func UUIDv4 ¶
func UUIDv4() *Config
UUIDv4 returns a validation object that checks for a valid UUID version 4
func (*Config) Description ¶
Description adds a description to the config
func (*Config) Expecting ¶
Expecting constructs a string that indicates what the required values were.
func (*Config) KeyJoin ¶
KeyJoin joins the keys that are accocuated to a validation config, and concatonates them.
type Language ¶
type PathValidationFunction ¶
type Payload ¶
func (Payload) WithFields ¶
WithFields does something, probably deprecated.
Source Files ¶
- cfg_arrayFloat64.go
- cfg_arrayInt.go
- cfg_arrayInterface.go
- cfg_arrayString.go
- cfg_base64decode.go
- cfg_bool.go
- cfg_country_alpha2.go
- cfg_country_alpha3.go
- cfg_emailAddress.go
- cfg_float64.go
- cfg_hex.go
- cfg_hex_decode.go
- cfg_hex_sha1.go
- cfg_hex_sha256.go
- cfg_int.go
- cfg_int64.go
- cfg_interface.go
- cfg_ipAddress.go
- cfg_language.go
- cfg_mapStringInterface.go
- cfg_password.go
- cfg_phone.go
- cfg_slice.go
- cfg_string.go
- cfg_stringExact.go
- cfg_stringSet.go
- cfg_stringSplit.go
- cfg_time.go
- cfg_url.go
- cfg_username.go
- cfg_uuidv4.go
- config.go
- const.go
- const_errors.go
- countries.go
- doc.go
- languages.go
- payloads.go
- sanitize.go