Documentation
¶
Index ¶
- Variables
- func Email(ctx context.Context, v string) error
- func EmailLookup(ctx context.Context, v string) error
- func EmailWeak(ctx context.Context, v string) error
- func Hostname(ctx context.Context, v string) error
- func MD5(ctx context.Context, v string) error
- func Meta(verb rune, value any) string
- func Optional[T any](ctx context.Context, v T) error
- func Required[T any](ctx context.Context, v T) error
- func URI(ctx context.Context, v string) error
- func URL(ctx context.Context, v string) error
- func UUID(ctx context.Context, v string) error
- func Valid[T Validator](ctx context.Context, v T) error
- type AnyRule
- type AnyRules
- type BoolRule
- type BoolRules
- type DynamicRule
- type Error
- type Float
- type Float32Rule
- type Float32Rules
- type Float64Rule
- type Float64Rules
- type Int32Rule
- type Int32Rules
- type Int64Rule
- type Int64Rules
- type Int8Rule
- type Int8Rules
- type IntRule
- type IntRules
- type Integer
- type InterfaceRule
- type InterfaceRules
- type Name
- type Number
- type Ordered
- type Rule
- func Dynamic[T any](fn func(ctx context.Context) error) Rule[T]
- func Equal[T comparable](expected T) Rule[T]
- func IsRequired[T any](expected bool) Rule[T]
- func NotEqual[T comparable](expected T) Rule[T]
- func NumberMax[T Number](expected T) Rule[T]
- func NumberMin[T Number](expected T) Rule[T]
- func NumberNotRange[T Number](min, max T) Rule[T]
- func NumberNotSize[T Number](expected T) Rule[T]
- func NumberRange[T Number](min, max T) Rule[T]
- func NumberSize[T Number](expected T) Rule[T]
- func Union[T any](rules ...Rule[T]) Rule[T]
- type Rules
- type StringRule
- func Match(alias string, regexp *regexp.Regexp) StringRule
- func NoPrefix(expected string) StringRule
- func NoSuffix(expected string) StringRule
- func NotMatch(alias string, regexp *regexp.Regexp) StringRule
- func Prefix(expected string) StringRule
- func StringBool(expectd bool) StringRule
- func StringContains(expected string) StringRule
- func StringMax(expected int) StringRule
- func StringMin(expected int) StringRule
- func StringNotContains(expected string) StringRule
- func StringNotRange(min, max int) StringRule
- func StringNotSize(expected int) StringRule
- func StringRange(min, max int) StringRule
- func StringSize(expected int) StringRule
- func Suffix(expected string) StringRule
- type StringRules
- type UInt32Rule
- type UInt32Rules
- type UInt64Rule
- type UInt64Rules
- type UInt8Rule
- type UInt8Rules
- type UIntRule
- type UIntRules
- type Validator
- type ValidatorRule
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrBreak = errors.New("break") ErrUnhandled = errors.New("unhandled type") )
View Source
var Alnum = Match(NameAlnum.String(), config.RegexAlnum)
View Source
var Alpha = Match(NameAlpha.String(), config.RegexAlpha)
View Source
var Numeric = Match(NameNumeric.String(), config.RegexNumeric)
Functions ¶
func EmailLookup ¶ added in v0.3.2
EmailLookup validation using simple regex
Types ¶
type DynamicRule ¶ added in v1.0.0
type Float ¶ added in v1.0.0
type Float = constraints.Float
type Float32Rule ¶
type Float32Rules ¶ added in v1.0.0
type Float64Rule ¶
type Float64Rules ¶ added in v1.0.0
type Int32Rules ¶ added in v1.0.0
type Int64Rules ¶ added in v1.0.0
type Integer ¶ added in v1.0.0
type Integer = constraints.Integer
type InterfaceRule ¶
type InterfaceRule = Rule[interface{}]
type InterfaceRules ¶ added in v1.0.0
type InterfaceRules = Rules[interface{}]
type Name ¶
type Name string
const NameAlnum Name = "alnum"
const NameAlpha Name = "alpha"
const NameBool Name = "bool"
const NameContains Name = "contains"
const NameEmail Name = "email"
const NameEqual Name = "equal"
const NameHostname Name = "hostname"
const NameMD5 Name = "md5"
const NameMatch Name = "match"
const NameMax Name = "max"
const NameMin Name = "min"
const NameNumeric Name = "numeric"
const NamePrefix Name = "prefix"
const NameRange Name = "range"
const NameRequired Name = "required"
const NameSize Name = "size"
const NameSuffix Name = "suffix"
const NameURI Name = "uri"
const NameURL Name = "url"
const NameUUID Name = "uuid"
const NameValid Name = "valid"
type Ordered ¶ added in v1.0.0
type Ordered = constraints.Ordered
type Rule ¶
func Dynamic ¶ added in v1.0.0
Example ¶
package main import ( "context" "fmt" "github.com/foomo/fender" "github.com/foomo/fender/fend" "github.com/foomo/fender/rule" ) func main() { err := fender.All(context.TODO(), fend.Field("demo", "foo", rule.Dynamic[string]( func(ctx context.Context) error { return rule.NewError("bar") }, )), ) fmt.Println(err) }
Output: demo:bar
func Equal ¶ added in v1.0.0
func Equal[T comparable](expected T) Rule[T]
func IsRequired ¶ added in v1.0.0
func NotEqual ¶ added in v1.0.0
func NotEqual[T comparable](expected T) Rule[T]
func NumberNotRange ¶ added in v1.0.0
func NumberNotSize ¶ added in v1.0.0
func NumberRange ¶ added in v1.0.0
func NumberSize ¶ added in v1.0.0
func Union ¶ added in v1.0.0
Example ¶
package main import ( "context" "fmt" "github.com/foomo/fender" "github.com/foomo/fender/fend" "github.com/foomo/fender/rule" ) func main() { { err := fender.All(context.TODO(), fend.Var("foo", rule.Union( rule.StringMin(10), rule.Equal("bar"), )), ) fmt.Println(err) } { err := fender.All(context.TODO(), fend.Var("foo", rule.Union( rule.StringMin(10), rule.Equal("foo"), )), ) fmt.Println(err) } }
Output: equal=bar <nil>
type StringRule ¶
func StringBool ¶ added in v1.0.0
func StringBool(expectd bool) StringRule
func StringContains ¶ added in v1.0.0
func StringContains(expected string) StringRule
func StringNotContains ¶ added in v1.0.0
func StringNotContains(expected string) StringRule
func StringNotRange ¶ added in v1.0.0
func StringNotRange(min, max int) StringRule
func StringNotSize ¶ added in v1.0.0
func StringNotSize(expected int) StringRule
func StringRange ¶ added in v1.0.0
func StringRange(min, max int) StringRule
func StringSize ¶ added in v1.0.0
func StringSize(expected int) StringRule
type StringRules ¶ added in v1.0.0
type UInt32Rule ¶
type UInt32Rules ¶ added in v1.0.0
type UInt64Rule ¶
type UInt64Rules ¶ added in v1.0.0
type UInt8Rules ¶ added in v1.0.0
type ValidatorRule ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.