mirror of
https://github.com/eolinker/apinto
synced 2025-12-24 13:28:15 +08:00
# Conflicts: # drivers/auth/apikey/driver.go # drivers/auth/basic/driver.go # drivers/discovery/static/driver.go # drivers/plugins/circuit-breaker/driver.go # drivers/plugins/cors/driver.go # drivers/plugins/extra-params/driver.go # drivers/plugins/gzip/driver.go # drivers/plugins/ip-restriction/driver.go # drivers/plugins/params-transformer/driver.go # drivers/plugins/proxy-rewrite/driver.go # drivers/plugins/proxy_rewrite_v2/driver.go # drivers/plugins/response-rewrite/driver.go # drivers/router/http-router/config.go # plugin-manager/factory.go # plugin-manager/manager.go # plugin/plugin.go # v2/router-http-driver/driver.go # v2/router-http-driver/register.go # v2/service-http/send_test.go # v2/service-http/service.go
59 lines
1.0 KiB
Go
59 lines
1.0 KiB
Go
package plugin
|
||
|
||
import (
|
||
"github.com/eolinker/eosc/eocontext"
|
||
"reflect"
|
||
)
|
||
|
||
//Config 普通插件配置,在router、service、upstream的插件格式
|
||
type Config struct {
|
||
Disable bool `json:"disable"`
|
||
Config interface{} `json:"config"`
|
||
}
|
||
|
||
type IPluginManager interface {
|
||
CreateRequest(id string, conf map[string]*Config) eocontext.IChain
|
||
GetConfigType(name string) (reflect.Type, bool)
|
||
|
||
//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
|
||
}
|