forked from go-chassis/go-chassis
/
panel.go
executable file
·52 lines (44 loc) · 1.52 KB
/
panel.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
package control
import (
"fmt"
"github.com/go-chassis/go-chassis/core/config"
"github.com/go-chassis/go-chassis/core/config/model"
"github.com/go-chassis/go-chassis/core/invocation"
"github.com/go-chassis/go-chassis/third_party/forked/afex/hystrix-go/hystrix"
)
var panelPlugin = make(map[string]func(options Options) Panel)
//DefaultPanel get fetch config
var DefaultPanel Panel
//Panel is a abstraction of pulling configurations from various of systems, and transfer different configuration into standardized model
//you can use different panel implementation to pull different of configs from Istio or Archaius
//TODO able to set configs
type Panel interface {
GetCircuitBreaker(inv invocation.Invocation, serviceType string) (string, hystrix.CommandConfig)
GetLoadBalancing(inv invocation.Invocation) LoadBalancingConfig
GetRateLimiting(inv invocation.Invocation, serviceType string) RateLimitingConfig
GetFaultInjection(inv invocation.Invocation) model.Fault
GetEgressRule(inv invocation.Invocation)
}
//Options is options
type Options struct {
Address string
}
//InstallPlugin install implementation
func InstallPlugin(name string, f func(options Options) Panel) {
panelPlugin[name] = f
}
//Init initialize DefaultPanel
func Init() error {
infra := config.GlobalDefinition.Panel.Infra
if infra == "" {
infra = "archaius"
}
f, ok := panelPlugin[infra]
if !ok {
return fmt.Errorf("do not support [%s] panel", infra)
}
DefaultPanel = f(Options{
Address: config.GlobalDefinition.Panel.Settings["address"],
})
return nil
}