Files
apinto/plugin/plugin.go
黄孟柱 eb0b3a0ed2 stage
2021-12-14 11:11:44 +08:00

63 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package plugin
import "github.com/eolinker/goku/filter"
//Config 普通插件配置在router、service、upstream的插件格式
type Config struct {
Disable bool `json:"disable"`
Config interface{} `json:"config"`
}
type IPluginConfig interface {
Config() map[string]Config
}
type IPlugin interface {
filter.IChain
Destroy()
}
type IPluginManager interface {
CreateRouter(id string, conf map[string]*Config) IPlugin
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(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
}