-
Notifications
You must be signed in to change notification settings - Fork 7
/
utilsOptions.go
49 lines (40 loc) · 1.1 KB
/
utilsOptions.go
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package zog
import (
"github.com/Oudwins/zog/conf"
p "github.com/Oudwins/zog/internals"
)
// Options that can be passed to a test
type TestOption = func(test *p.Test)
// Message is a function that allows you to set a custom message for the test.
func Message(msg string) TestOption {
return func(test *p.Test) {
test.ErrFmt = func(e p.ZogError, p ParseCtx) {
e.SetMessage(msg)
}
}
}
// MessageFunc is a function that allows you to set a custom message formatter for the test.
func MessageFunc(fn p.ErrFmtFunc) TestOption {
return func(test *p.Test) {
test.ErrFmt = fn
}
}
// Options that can be passed to a `schema.New()` call
type SchemaOption = func(s ZogSchema)
func WithCoercer(c conf.CoercerFunc) SchemaOption {
return func(s ZogSchema) {
s.setCoercer(c)
}
}
// Options that can be passed to a `schema.Parse()` call
type ParsingOption = func(p *p.ZogParseCtx)
func WithErrFormatter(fmter p.ErrFmtFunc) ParsingOption {
return func(p *p.ZogParseCtx) {
p.SetErrFormatter(fmter)
}
}
func WithCtxValue(key string, val any) ParsingOption {
return func(p *p.ZogParseCtx) {
p.Set(key, val)
}
}