forked from ligato/vpp-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
45 lines (35 loc) · 1.05 KB
/
options.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
package telemetry
import (
"go.ligato.io/cn-infra/v2/rpc/grpc"
"go.ligato.io/cn-infra/v2/rpc/prometheus"
"go.ligato.io/cn-infra/v2/rpc/rest"
"go.ligato.io/cn-infra/v2/servicelabel"
"go.ligato.io/vpp-agent/v3/plugins/govppmux"
"go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin"
)
// DefaultPlugin is default instance of Plugin
var DefaultPlugin = *NewPlugin()
// NewPlugin creates a new Plugin with the provided Options
func NewPlugin(opts ...Option) *Plugin {
p := &Plugin{}
p.PluginName = "telemetry"
p.ServiceLabel = &servicelabel.DefaultPlugin
p.VPP = &govppmux.DefaultPlugin
p.Prometheus = &prometheus.DefaultPlugin
p.GRPC = &grpc.DefaultPlugin
p.HTTPHandlers = &rest.DefaultPlugin
p.IfPlugin = &ifplugin.DefaultPlugin
for _, o := range opts {
o(p)
}
p.PluginDeps.Setup()
return p
}
// Option is a function that acts on a Plugin to inject Dependencies or configuration
type Option func(*Plugin)
// UseDeps returns Option that can inject custom dependencies.
func UseDeps(cb func(*Deps)) Option {
return func(p *Plugin) {
cb(&p.Deps)
}
}