-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflow_test.go
More file actions
27 lines (22 loc) · 581 Bytes
/
flow_test.go
File metadata and controls
27 lines (22 loc) · 581 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package valis_test
import (
"fmt"
"github.com/soranoba/valis"
"github.com/soranoba/valis/is"
"reflect"
)
func ExampleWhen() {
v := valis.NewValidator()
isInt := func(ctx *valis.WhenContext) bool {
return reflect.ValueOf(ctx.Value()).Kind() == reflect.Int
}
if err := v.Validate(0, valis.When(isInt, is.NonZero)); err != nil {
fmt.Println(err)
}
if err := v.Validate("1", valis.When(isInt, is.NonZero).Else(is.In("a", "b", "c"))); err != nil {
fmt.Println(err)
}
// Output:
// (non_zero) can't be blank (or zero)
// (inclusion) is not included in [a b c]
}