forked from ligato/vpp-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
47 lines (38 loc) · 1.11 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
46
47
package l3plugin
import (
"github.com/ligato/cn-infra/config"
"github.com/ligato/cn-infra/logging"
"github.com/ligato/vpp-agent/plugins/kvscheduler"
"github.com/ligato/vpp-agent/plugins/linux/ifplugin"
"github.com/ligato/vpp-agent/plugins/linux/nsplugin"
)
// DefaultPlugin is a default instance of IfPlugin.
var DefaultPlugin = *NewPlugin()
// NewPlugin creates a new Plugin with the provides Options
func NewPlugin(opts ...Option) *L3Plugin {
p := &L3Plugin{}
p.PluginName = "linux-l3plugin"
p.KVScheduler = &kvscheduler.DefaultPlugin
p.NsPlugin = &nsplugin.DefaultPlugin
p.IfPlugin = &ifplugin.DefaultPlugin
for _, o := range opts {
o(p)
}
if p.Log == nil {
p.Log = logging.ForPlugin(p.String())
}
if p.Cfg == nil {
p.Cfg = config.ForPlugin(p.String(),
config.WithCustomizedFlag(config.FlagName(p.String()), "linux-l3plugin.conf"),
)
}
return p
}
// Option is a function that can be used in NewPlugin to customize Plugin.
type Option func(*L3Plugin)
// UseDeps returns Option that can inject custom dependencies.
func UseDeps(f func(*Deps)) Option {
return func(p *L3Plugin) {
f(&p.Deps)
}
}