upstream 对接插件

This commit is contained in:
黄孟柱
2021-11-12 16:52:50 +08:00
parent 7dfd612e3d
commit fd89f3ef88
7 changed files with 207 additions and 65 deletions

View File

@@ -16,3 +16,42 @@ type IPluginManager interface {
CreateService(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(low)
}
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
}