-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoptions.go
60 lines (52 loc) · 1.14 KB
/
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
51
52
53
54
55
56
57
58
59
60
package metadata
type options struct {
headers map[string]string // value为新的header key, value == ""使用原key
prefixes map[string]string // value为前缀替换
}
type Option func(option *options)
func evaluateOptions(opts []Option) *options {
opt := &options{
headers: make(map[string]string),
prefixes: make(map[string]string),
}
for _, o := range opts {
o(opt)
}
return opt
}
func WithHeader(header string) Option {
return func(option *options) {
if _, ok := option.headers[header]; ok {
return
} else {
option.headers[header] = ""
}
}
}
func WithHeaderReplace(header, replace string) Option {
return func(option *options) {
if _, ok := option.headers[header]; ok {
return
} else {
option.headers[header] = replace
}
}
}
func WithPrefix(prefix string) Option {
return func(option *options) {
if _, ok := option.prefixes[prefix]; ok {
return
} else {
option.prefixes[prefix] = prefix
}
}
}
func WithPrefixReplace(prefix, replace string) Option {
return func(option *options) {
if _, ok := option.prefixes[prefix]; ok {
return
} else {
option.prefixes[prefix] = replace
}
}
}