Documentation ¶
Index ¶
- Constants
- Variables
- func ByteLength(str string, params ...string) (result bool)
- func IsRequestURI(rawurl string) bool
- func IsRequestURL(rawurl string) bool
- func IsURL(str string) bool
- func StringLength(str string, params ...string) (result bool)
- func ToInt(str string) (result int64, err error)
- func Validate(s interface{}) (result bool, err error)
- type Bool
- func (b Bool) MarshalJSON() ([]byte, error)
- func (b Bool) MarshalText() ([]byte, error)
- func (b Bool) Ptr() *bool
- func (b *Bool) Scan(value interface{}) (err error)
- func (b *Bool) SetValid(v bool)
- func (b *Bool) UnmarshalJSON(data []byte) (err error)
- func (b *Bool) UnmarshalText(text []byte) (err error)
- func (b Bool) Value() (driver.Value, error)
- type CustomTypeValidator
- type Error
- type Errors
- type Int
- type ParamValidator
- type String
- func (s String) MarshalJSON() ([]byte, error)
- func (s String) MarshalText() ([]byte, error)
- func (s String) Ptr() *string
- func (s *String) Scan(value interface{}) (err error)
- func (s *String) SetValid(v string)
- func (s *String) UnmarshalJSON(data []byte) (err error)
- func (s *String) UnmarshalText(text []byte) (err error)
- func (s String) Value() (driver.Value, error)
- type Time
- func (t Time) MarshalJSON() ([]byte, error)
- func (t Time) MarshalText() ([]byte, error)
- func (t Time) Ptr() *time.Time
- func (t *Time) Scan(value interface{}) (err error)
- func (t *Time) SetValid(v time.Time)
- func (t *Time) UnmarshalJSON(data []byte) (err error)
- func (t *Time) UnmarshalText(text []byte) (err error)
- func (t Time) Value() (driver.Value, error)
- type Validator
Constants ¶
const ( IP string = `` /* 659-byte string literal not displayed */ URLSchema string = `((ftp|tcp|udp|wss?|https?):\/\/)` URLUsername string = `(\S+(:\S*)?@)` URLIP string = `([1-9]\d?|1\d\d|2[01]\d|22[0-3])(\.(1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.([0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))` URLSubdomain string = `((www\.)|([a-zA-Z0-9]([-\.][a-zA-Z0-9]+)*))` URLPort string = `(:(\d{1,5}))` URLPath string = `((\/|\?|#)[^\s]*)` URL string = `^` + URLSchema + `?` + URLUsername + `?` + `((` + URLIP + `|(\[` + IP + `\])|(([a-zA-Z0-9]([a-zA-Z0-9-]+)?[a-zA-Z0-9]([-\.][a-zA-Z0-9]+)*)|(` + URLSubdomain + `?))?(([a-zA-Z\x{00a1}-\x{ffff}0-9]+-?-?)*[a-zA-Z\x{00a1}-\x{ffff}0-9]+)(?:\.([a-zA-Z\x{00a1}-\x{ffff}]{1,}))?))` + URLPort + `?` + URLPath + `?$` )
Variables ¶
var CustomTypeTagMap = &customTypeTagMap{validators: make(map[string]CustomTypeValidator)}
CustomTypeTagMap is a map of functions that can be used as tags for Validate function.
var ParamTagMap = map[string]ParamValidator{ "length": ByteLength, "stringlength": StringLength, }
ParamTagMap is a map of functions accept variants parameters.
var ParamTagRegexMap = map[string]*regexp.Regexp{ "length": regexp.MustCompile("^length\\((\\d+)\\|(\\d+)\\)$"), "stringlength": regexp.MustCompile("^stringlength\\((\\d+)\\|(\\d+)\\)$"), }
ParamTagRegexMap maps param tags to their respective regexes.
var TagMap = map[string]Validator{ "url": IsURL, "requrl": IsRequestURL, "requri": IsRequestURI, }
TagMap is a map of functions, that can be used as tags for Validate function.
Functions ¶
func ByteLength ¶
ByteLength check string's length.
func IsRequestURI ¶ added in v1.1.0
IsRequestURI check if the string rawurl, assuming it was recieved in an HTTP request, is an absolute URI or an absolute path.
func IsRequestURL ¶ added in v1.1.0
IsRequestURL check if the string rawurl, assuming it was recieved in an HTTP request, is a valid URL confirm to RFC 3986.
func StringLength ¶
StringLength check string's length(including multi byte strings)
Types ¶
type Bool ¶
Bool is a nullable bool. If key is assigned and value is not null, Bool is specified value, Null is false, Valid is true. If value is null, Null is true. If key is not assigned, Valid is false.
func BoolFromPtr ¶
BoolFromPtr creates a new Bool that will be null if b is nil
func (Bool) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Bool) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (Bool) Ptr ¶
Ptr returns a pointer to this Bool's value, or a nil pointer if this Bool is null or not valid.
func (*Bool) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Bool) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type CustomTypeValidator ¶
type CustomTypeValidator func(i interface{}, o interface{}) bool
CustomTypeValidator is a wrapper for validator functions that returns bool and accept any type. The second parameter should be the context (in the case of validating a struct: the whole object being validated)
type Error ¶
Error encapsulates a name, an error and whether there is a custom error message or not.
type Errors ¶
type Errors []error
Errors is an array of multiple errors and conforms to the error interface.
type Int ¶
Int is a nullable int.
func IntFromPtr ¶
IntFromPtr creates a new Int that be null if i is nil.
func (Int) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Int) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (Int) Ptr ¶
Ptr returns a pointer to this Int's value, or a nil pointer if this Int is null or not valid.
func (*Int) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Int) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type ParamValidator ¶
ParamValidator is a wrapper for validator functions.
type String ¶
String is a nullable string.
func StringFrom ¶
StringFrom creates a new String that will never be blank.
func StringFromPtr ¶
StringFromPtr creates a new String that be null if s is nil.
func (String) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (String) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (String) Ptr ¶
Ptr returns a pointer to this String's value, or a nil pointer if this String is null or not valid.
func (*String) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*String) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Time ¶
Time is a nullable Time.
func TimeFromPtr ¶
TimeFromPtr creates a new Time that will be null if t is nil.
func (Time) MarshalJSON ¶
MarshalJSON implements encoding/json.Marshaler. It will encode null if this time is null.
func (Time) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (Time) Ptr ¶
Ptr returns a pointer to this Time value, or a nil pointer if this Time is null or not valid.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements encoding/json.Unmarshaler. It supports string, object, and null input.
func (*Time) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.