-
Notifications
You must be signed in to change notification settings - Fork 12
/
unmarshaler_options.go
50 lines (41 loc) · 1.32 KB
/
unmarshaler_options.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
50
// Code generated by "go-option -type=Unmarshaler"; DO NOT EDIT.
// Install go-option by "go get install github.com/searKing/golang/tools/go-option"
package protojson
// A UnmarshalerOption sets options.
type UnmarshalerOption interface {
apply(*Unmarshaler)
}
// EmptyUnmarshalerOption does not alter the configuration. It can be embedded
// in another structure to build custom options.
//
// This API is EXPERIMENTAL.
type EmptyUnmarshalerOption struct{}
func (EmptyUnmarshalerOption) apply(*Unmarshaler) {}
// UnmarshalerOptionFunc wraps a function that modifies Unmarshaler into an
// implementation of the UnmarshalerOption interface.
type UnmarshalerOptionFunc func(*Unmarshaler)
func (f UnmarshalerOptionFunc) apply(do *Unmarshaler) {
f(do)
}
// ApplyOptions call apply() for all options one by one
func (o *Unmarshaler) ApplyOptions(options ...UnmarshalerOption) *Unmarshaler {
for _, opt := range options {
if opt == nil {
continue
}
opt.apply(o)
}
return o
}
// WithUnmarshaler sets Unmarshaler.
func WithUnmarshaler(v Unmarshaler) UnmarshalerOption {
return UnmarshalerOptionFunc(func(o *Unmarshaler) {
*o = v
})
}
// sample code for option, default for nothing to change
func _UnmarshalerOptionWithDefault() UnmarshalerOption {
return UnmarshalerOptionFunc(func(*Unmarshaler) {
// nothing to change
})
}