validate

package
v1.6.4 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFileSizeToHigh = fmt.Errorf("file size to high")
View Source
var ErrFileSizeToLow = fmt.Errorf("file size to low")
View Source
var ErrFileSizeToLowForValidation = fmt.Errorf("file size to low for validation")
View Source
var ErrUnknownFileType = fmt.Errorf("define a supported type")
View Source
var ErrWrongFileType = fmt.Errorf("wrong file type")

Functions

func AllMessages

func AllMessages() []string

func File

func File(src io.Reader, rules Rules) ([]byte, error)

func Struct

func Struct(v interface{}) error

Struct validates the interface by the struct tag `validate` Example

type Customer struct {
	Age   int    `validate:"required=true,min=5,max=10"`
	Email string `validate:"required=true,email=true"`
}

Types

type Error

type Error struct {
	//I for index or key map, makes it easier to locate where msg belongs
	I   interface{} `json:"i,omitempty"`
	Msg string      `json:"msg"`
}

func (Error) Error

func (me Error) Error() string

func (Error) String

func (me Error) String() string

type ErrorMap

type ErrorMap map[string]Errors

func (ErrorMap) Error

func (me ErrorMap) Error() string

func (ErrorMap) String

func (me ErrorMap) String() string

func (ErrorMap) Translate

func (me ErrorMap) Translate(trans func(key string, args ...string) string)

type Errors

type Errors []*Error

func Field

func Field(val interface{}, rules Rules) Errors

Field validates a val with the given rules

func FieldByStrRules

func FieldByStrRules(val interface{}, rules string) Errors

FieldByStrRules accepts rules like "required=true,email=true,matches=^(abc|123)$"

func (Errors) Error

func (me Errors) Error() string

func (*Errors) Translate

func (me *Errors) Translate(trans func(key string, args ...string) string)

type FTypes

type FTypes struct {
	Vague map[string][]types.Type
	Exact sync.Map
}

func FileTypes

func FileTypes() FTypes

type FileType

type FileType struct {
	Exact bool   `json:"exact"` //vague                  or exact
	Kind  string `json:"kind"`  //(image,video,audio...) or (jpg,png,mp4,mp3...)
}

type Rules

type Rules map[string]interface{}

Rules used for validation

func (Rules) FileType

func (r Rules) FileType() *FileType

Jump to

Keyboard shortcuts

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