-
Notifications
You must be signed in to change notification settings - Fork 198
/
plugin.go
61 lines (53 loc) · 1.09 KB
/
plugin.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
61
package plugin
import "github.com/eolinker/apinto/filter"
//Config 普通插件配置,在router、service、upstream的插件格式
type Config struct {
Disable bool `json:"disable"`
Config interface{} `json:"config"`
}
type IPluginConfigMerge interface {
Merge(high map[string]*Config) map[string]*Config
}
type IPlugin interface {
filter.IChain
Destroy()
}
type IPluginManager interface {
CreateRequest(id string, conf map[string]*Config) IPlugin
//CreateUpstream(id string, conf map[string]*Config) IPlugin
}
func MergeConfig(high, low map[string]*Config) map[string]*Config {
if high == nil && low == nil {
return make(map[string]*Config)
}
if high == nil {
return clone(low)
}
if low == nil {
return clone(high)
}
mv := clone(low)
for k, hv := range high {
lv, has := mv[k]
if has {
*lv = *hv
} else {
c := new(Config)
*c = *hv
mv[k] = c
}
}
return mv
}
func clone(v map[string]*Config) map[string]*Config {
cv := make(map[string]*Config)
if v == nil {
return cv
}
for k, v := range v {
c := new(Config)
*c = *v
cv[k] = c
}
return cv
}