go.ligato.io/vpp-agent/v3@v3.5.0/plugins/govppmux/options.go (about) 1 // Copyright (c) 2019 Cisco and/or its affiliates. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at: 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package govppmux 16 17 import ( 18 "go.ligato.io/cn-infra/v2/datasync/resync" 19 "go.ligato.io/cn-infra/v2/health/statuscheck" 20 "go.ligato.io/cn-infra/v2/rpc/rest" 21 ) 22 23 // DefaultPlugin is default instance of Plugin 24 var DefaultPlugin = *NewPlugin() 25 26 // NewPlugin creates a new Plugin with the provides Options 27 func NewPlugin(opts ...Option) *Plugin { 28 p := &Plugin{} 29 30 p.PluginName = "govpp" 31 p.HTTPHandlers = &rest.DefaultPlugin 32 p.StatusCheck = &statuscheck.DefaultPlugin 33 p.Resync = &resync.DefaultPlugin 34 35 for _, o := range opts { 36 o(p) 37 } 38 39 p.PluginDeps.Setup() 40 41 return p 42 } 43 44 // Option is a function that acts on a Plugin to inject Dependencies or configuration 45 type Option func(*Plugin) 46 47 // UseDeps returns Option that can inject custom dependencies. 48 func UseDeps(cb func(*Deps)) Option { 49 return func(p *Plugin) { 50 cb(&p.Deps) 51 } 52 }