-
Notifications
You must be signed in to change notification settings - Fork 3
/
option.go
51 lines (43 loc) · 887 Bytes
/
option.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
51
package jsonRespKit
import (
"github.com/richelieu-yang/chimera/v2/src/json/jsonKit"
)
type (
options struct {
api jsonKit.API
filePathSlice []string
fileDataSlice []*FileData
}
Option func(opts *options)
)
// WithAPI
/*
@param api sonic.ConfigDefault(默认; 推荐) || jsoniter.ConfigDefault
*/
func WithAPI(api jsonKit.API) Option {
return func(opts *options) {
opts.api = api
}
}
func WithFilePathSlice(filePathSlice []string) Option {
return func(opts *options) {
opts.filePathSlice = filePathSlice
}
}
func WithFileDataSlice(fileDataSlice []*FileData) Option {
return func(opts *options) {
opts.fileDataSlice = fileDataSlice
}
}
func loadOptions(optionSlice ...Option) *options {
opts := &options{
api: nil,
}
for _, option := range optionSlice {
option(opts)
}
if opts.api == nil {
opts.api = jsonKit.GetDefaultApi()
}
return opts
}