govalidator: github.com/thedevsaddam/govalidator Index | Files

package govalidator

import "github.com/thedevsaddam/govalidator"

Index

Package Files

errors.go helper.go regex_patterns.go roller.go rules.go type.go utils.go utils110.go validate_file.go validator.go

Constants

const (
    Alpha string = "^[a-zA-Z]+$"

    AlphaDash string = "^[a-zA-Z0-9_-]+$"

    AlphaSpace string = "^[-a-zA-Z0-9_ ]+$"

    AlphaNumeric string = "^[a-zA-Z0-9]+$"

    CreditCard string = "" /* 156 byte string literal not displayed */

    Coordinate string = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?),\\s*[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$"

    CSSColor string = "^(#([\\da-f]{3}){1,2}|(rgb|hsl)a\\((\\d{1,3}%?,\\s?){3}(1|0?\\.\\d+)\\)|(rgb|hsl)\\(\\d{1,3}%?(,\\s?\\d{1,3}%?){2}\\))$"

    Date string = "" /* 233 byte string literal not displayed */

    DateDDMMYY string = "^(0?[1-9]|[12][0-9]|3[01])[\\/\\-](0?[1-9]|1[012])[\\/\\-]\\d{4}$"

    Digits string = "^[+-]?([0-9]*\\.?[0-9]+|[0-9]+\\.?[0-9]*)([eE][+-]?[0-9]+)?$"

    Email string = "" /* 135 byte string literal not displayed */

    Float string = "^(?:[-+]?(?:[0-9]+))?(?:\\.[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$"

    IP  string = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"

    IPV4 string = "^([0-9]{1,3}\\.){3}[0-9]{1,3}(\\/([0-9]|[1-2][0-9]|3[0-2]))?$"

    IPV6 string = "" /* 1059 byte string literal not displayed */

    Latitude string = "^(\\+|-)?(?:90(?:(?:\\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\\.[0-9]{1,6})?))$"

    Longitude string = "^(\\+|-)?(?:180(?:(?:\\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\\.[0-9]{1,6})?))$"

    Numeric string = "^-?[0-9]+$"

    URL string = "^(?:http(s)?:\\/\\/)?[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]@!\\$&'\\(\\)\\*\\+,;=.]+$"

    UUID string = "^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$"

    UUID3 string = "^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$"

    UUID4 string = "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"

    UUID5 string = "^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
)

func AddCustomRule Uses

func AddCustomRule(name string, fn func(field string, rule string, message string, value interface{}) error)

AddCustomRule help to add custom rules for validator First argument it takes the rule name and second arg a func Second arg must have this signature below fn func(name string, fn func(field string, rule string, message string, value interface{}) error see example in readme: https://github.com/thedevsaddam/govalidator#add-custom-rules

type Bool Uses

type Bool struct {
    Value bool `json:"value"`
    IsSet bool `json:"isSet"`
}

Bool describes a custom type of built-in bool data type

func (*Bool) MarshalJSON Uses

func (i *Bool) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (*Bool) UnmarshalJSON Uses

func (i *Bool) UnmarshalJSON(data []byte) error

UnmarshalJSON ...

type Float32 Uses

type Float32 struct {
    Value float32 `json:"value"`
    IsSet bool    `json:"isSet"`
}

Float32 describes a custom type of built-in float32 data type

func (*Float32) MarshalJSON Uses

func (i *Float32) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (*Float32) UnmarshalJSON Uses

func (i *Float32) UnmarshalJSON(data []byte) error

UnmarshalJSON ...

type Float64 Uses

type Float64 struct {
    Value float64 `json:"value"`
    IsSet bool    `json:"isSet"`
}

Float64 describes a custom type of built-in float64 data type

func (*Float64) MarshalJSON Uses

func (i *Float64) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (*Float64) UnmarshalJSON Uses

func (i *Float64) UnmarshalJSON(data []byte) error

UnmarshalJSON ...

type Int Uses

type Int struct {
    Value int  `json:"value"`
    IsSet bool `json:"isSet"`
}

Int describes a custom type of built-in int data type

func (*Int) MarshalJSON Uses

func (i *Int) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (*Int) UnmarshalJSON Uses

func (i *Int) UnmarshalJSON(data []byte) error

UnmarshalJSON ...

type Int64 Uses

type Int64 struct {
    Value int64 `json:"value"`
    IsSet bool  `json:"isSet"`
}

Int64 describes a custom type of built-in int64 data type

func (*Int64) MarshalJSON Uses

func (i *Int64) MarshalJSON() ([]byte, error)

MarshalJSON ...

func (*Int64) UnmarshalJSON Uses

func (i *Int64) UnmarshalJSON(data []byte) error

UnmarshalJSON ...

type MapData Uses

type MapData map[string][]string

MapData represents basic data structure for govalidator Rules and Messages

type Options Uses

type Options struct {
    Data            interface{} // Data represents structure for JSON body
    Request         *http.Request
    RequiredDefault bool    // RequiredDefault represents if all the fields are by default required or not
    Rules           MapData // Rules represents rules for form-data/x-url-encoded/query params data
    Messages        MapData // Messages represents custom/localize message for rules
    TagIdentifier   string  // TagIdentifier represents struct tag identifier, e.g: json or validate etc
    FormSize        int64   //Form represents the multipart forom data max memory size in bytes
}

Options describes configuration option for validator

type Validator Uses

type Validator struct {
    Opts Options // Opts contains all the options for validator
}

Validator represents a validator with options

func New Uses

func New(opts Options) *Validator

New return a new validator object using provided options

func (*Validator) SetDefaultRequired Uses

func (v *Validator) SetDefaultRequired(required bool)

SetDefaultRequired change the required behavior of fields Default value if false If SetDefaultRequired set to true then it will mark all the field in the rules list as required

func (*Validator) SetTagIdentifier Uses

func (v *Validator) SetTagIdentifier(identifier string)

SetTagIdentifier change the default tag identifier (json) to your custom tag.

func (*Validator) Validate Uses

func (v *Validator) Validate() url.Values

Validate validate request data like form-data, x-www-form-urlencoded and query params see example in README.md file ref: https://github.com/thedevsaddam/govalidator#example

func (*Validator) ValidateJSON Uses

func (v *Validator) ValidateJSON() url.Values

ValidateJSON validate request data from JSON body to Go struct see example in README.md file

func (*Validator) ValidateStruct Uses

func (v *Validator) ValidateStruct() url.Values

Package govalidator imports 14 packages (graph) and is imported by 2 packages. Updated 2019-02-08. Refresh now. Tools for package owners.