validation

package
v0.0.0-...-3a6b306 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2019 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	ERR_INVALID_CHARS = "PARAM CONTENTS INVALID"
	ERR_RANGE_EXCEED  = "PARAM VALUE IS OUT OF RANGE BOUNDS"

	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"
)
View Source
const (
	COUNTRY_CSV = `` /* 21691-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func Countries

func Countries() map[string]*Country

func Hash256

func Hash256(input string) string

func IsAlpha

func IsAlpha(s string) (bool, string)

func IsAlphanumeric

func IsAlphanumeric(s string) (bool, string)

func Languages

func Languages() map[string]*Language

func ReverseCountries

func ReverseCountries() map[string]*Country

func Sanitize

func Sanitize(s string) string

Types

type BodyValidationFunction

type BodyValidationFunction func(web.RequestInterface, interface{}) (*web.ResponseStatus, interface{})

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 ArrayInt

func ArrayInt() *Config

Returns a validation object that checks for a slice of integers

func ArrayInterface

func ArrayInterface() *Config

Returns a validation object for request body that checks a property to see if it's an array

func ArrayString

func ArrayString() *Config

Returns a validation object that allows any value

func Base64Decode

func Base64Decode() *Config

Returns a validation object which checks for valid username

func Bool

func Bool() *Config

Returns a validation object that checks for a bool which parses correctly

func CountryISO2

func CountryISO2() *Config

Returns a validation object that checks to see if it can resolve to a country struct

func EmailAddress

func EmailAddress() *Config

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 Float64

func Float64(ranges ...int) *Config

Returns a validation object that checks for a float64 which parses correctly

func Hex

func Hex(min, max float64) *Config

Returns a validation object that checks for a hex string with a length within optional range

func Hex256

func Hex256() *Config

Returns a validation object that checks for a hex string with fixed range

func HexDecode

func HexDecode(min, max float64) *Config

Returns a validation object that decodes a hex string with a length within optional range

func IPv4Address

func IPv4Address() *Config

Returns a validation object that checks for a string with a length within optional range

func Int

func Int() *Config

Returns a validation object that checks for an int which parses correctly

func Int64

func Int64() *Config

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

Returns a validation object that allows any value

func Json

func Json() *Config

Returns a validation object which checks for (in)valid json

func LanguageISO2

func LanguageISO2() *Config

Returns a validation object that checks to see if it can resolve to a country struct

func MapStringInterface

func MapStringInterface() *Config

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

func Now

func Now() *Config

Returns a validation object which outputs the current time

func PasswordHard

func PasswordHard() *Config

Returns a validation object which checks for password

func PasswordWeak

func PasswordWeak() *Config

Returns a validation object which checks for password

func PhoneNumber

func PhoneNumber(countryCode string) *Config

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

Returns a validation object which checks for valid time

func String

func String(min, max float64) *Config

Returns a validation object that checks for a string with a length within optional range

func StringExact

func StringExact(max float64) *Config

Returns a validation object that checks for a string with exact length

func StringInterfaceArray

func StringInterfaceArray() *Config

Returns a validation object for request body that checks a property to see if it's an array

func StringSet

func StringSet(set ...string) *Config

Returns a validation object which ensures string is whitelisted

func StringSplit

func StringSplit(delimiter string) *Config

Returns a validation object which checks for delimiter-separated string like CSV

func Time

func Time(layout string) *Config

Returns a validation object which checks for valid time like 2017-06-23T00:00:00.000Z

func UUIDv4

func UUIDv4() *Config

Returns a validation object that checks for a valid UUID version 4

func Url

func Url() *Config

Returns a validation object which checks for valid url

func Username

func Username(min, max float64) *Config

Returns a validation object which checks for valid username

func (*Config) Default

func (vc *Config) Default(x interface{}) *Config

Adds a default value to the config

func (*Config) Description

func (vc *Config) Description(x string) *Config

Adds a description to the config

func (*Config) Expecting

func (vc *Config) Expecting() string

func (*Config) Key

func (vc *Config) Key() string

Returns the first key associated with the path parameter

func (*Config) KeyJoin

func (vc *Config) KeyJoin(delim string) string

func (*Config) Required

func (vc *Config) Required() *Config

Signifies that the field is 'required'

func (*Config) Summary

func (vc *Config) Summary(x string) *Config

Adds a description to the config

type Country

type Country struct {
	Name string `json:"name"`
	Code string `json:"code"`
	Lat  string `json:"lat"`
	Lng  string `json:"lng"`
	Lang string `json:"lang"`
}

type IPv4

type IPv4 [4]int

func (IPv4) String

func (ipv4 IPv4) String() string

type JSON

type JSON struct{}

type Language

type Language struct {
	Code    string            `json:"code"`
	Native  string            `json:"native"`
	Names   map[string]string `json:"names"`
	Reverse bool              `json:"reversed"`
}

func Lang

func Lang(code, native string, rev bool) *Language

type PathValidationFunction

type PathValidationFunction func(web.RequestInterface, string) (*web.ResponseStatus, interface{})

type Spec

type Spec struct {
	Type string
	Keys []string
}

type URL

type URL struct{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL