Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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() { email := fend.NewRules(rule.StringMin(5), rule.Email) phone := fend.NewRules(rule.StringMin(3), rule.Numeric) emailOrPhone := fend.NewRules(fend.Union(email, phone)) { err := fender.All(context.TODO(), fend.Var("foo", fend.Union(email, phone)), ) fmt.Println(err) } { err := fender.All(context.TODO(), emailOrPhone.Var("foo"), ) fmt.Println(err) } { err := fender.All(context.TODO(), fend.Var("foo@bar.com", fend.Union(email, phone)), ) fmt.Println(err) } { err := fender.All(context.TODO(), emailOrPhone.Var("foo@bar.com"), ) fmt.Println(err) } { err := fender.All(context.TODO(), fend.Var("123456", fend.Union(email, phone)), ) fmt.Println(err) } { err := fender.All(context.TODO(), emailOrPhone.Var("123456"), ) fmt.Println(err) } }
Output: numeric=^[0-9]+$ numeric=^[0-9]+$ <nil> <nil> <nil> <nil>
Types ¶
type Error ¶ added in v1.0.0
func NewRuleError ¶ added in v1.0.0
type Fend ¶
func DynamicField ¶ added in v1.0.0
func DynamicField(path string, rules ...rule.DynamicRule) Fend
func DynamicVar ¶ added in v1.0.0
func DynamicVar(rules ...rule.DynamicRule) Fend
type Rules ¶ added in v1.0.0
func (Rules[T]) DynamicField ¶ added in v1.0.0
func (r Rules[T]) DynamicField(path string, rules ...rule.DynamicRule) Fend
func (Rules[T]) DynamicVar ¶ added in v1.0.0
func (r Rules[T]) DynamicVar(rules ...rule.DynamicRule) Fend
Click to show internal directories.
Click to hide internal directories.