validate

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2021 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRule

func AddRule(name string, inputFunc InputFunc, kinds Kinds)

AddRule adds a rule to the list of validation functions

func InputInt

func InputInt(kind reflect.Kind, value string) interface{}

InputInt always returns an int

func InputRegexp

func InputRegexp(kind reflect.Kind, value string) interface{}

InputRegexp always returns a compiled regular expression

func InputSame

func InputSame(kind reflect.Kind, value string) interface{}

InputSame returns the type matching the field

Types

type Field

type Field struct {
	Index *int
	Field *reflect.StructField
}

Field is always an array/slice index or struct field

type Fields

type Fields []Field

Fields is a list of Field

func (Fields) String

func (f Fields) String() string

func (Fields) ToString

func (f Fields) ToString(tag string) string

ToString converts a list of fields to a string using the given struct tag

type InputFunc

type InputFunc func(reflect.Kind, string) interface{}

InputFunc is a function that converts the parameter of a validation rule to the desired type

type Kinds

type Kinds map[reflect.Kind]ValidationFunc

Kinds is a map with validation funcs for each reflect.Kind

type ValidateValuer added in v0.2.0

type ValidateValuer interface {
	ValidateValue() interface{}
}

type ValidationError

type ValidationError struct {
	Field Fields
	Check string
	Value string
}

ValidationError contains information about a failed validation

func Validate

func Validate(v interface{}) []ValidationError

Validate validates a variable

func (ValidationError) String

func (e ValidationError) String() string

type ValidationFunc

type ValidationFunc func(reflect.Value, interface{}) bool

ValidationFunc is a function to validate a field

Jump to

Keyboard shortcuts

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