Total Lines | 24 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package validation_test |
||
2 | |||
3 | import ( |
||
4 | "fmt" |
||
5 | |||
6 | "github.com/muonsoft/validation" |
||
7 | "github.com/muonsoft/validation/validator" |
||
8 | ) |
||
9 | |||
10 | func ExampleNewCustomStringConstraint() { |
||
11 | validate := func(s string) bool { |
||
12 | return s == "valid" |
||
13 | } |
||
14 | constraint := validation.NewCustomStringConstraint( |
||
15 | validate, |
||
16 | "ExampleConstraint", // constraint name |
||
17 | "exampleCode", // violation code |
||
18 | "Unexpected value.", // violation message template |
||
19 | ) |
||
20 | |||
21 | s := "foo" |
||
22 | err := validator.ValidateString(&s, constraint) |
||
23 | |||
24 | fmt.Println(err) |
||
25 | // Output: |
||
28 |