mirror of
https://github.com/eolinker/apinto
synced 2025-12-24 13:28:15 +08:00
upstream 对接插件
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user