go.ligato.io/vpp-agent/v3@v3.5.0/plugins/restapi/options.go (about)

     1  //  Copyright (c) 2018 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 restapi
    16  
    17  import (
    18  	"go.ligato.io/cn-infra/v2/rpc/rest"
    19  	"go.ligato.io/cn-infra/v2/servicelabel"
    20  	"go.ligato.io/vpp-agent/v3/plugins/govppmux"
    21  	"go.ligato.io/vpp-agent/v3/plugins/kvscheduler"
    22  	linuxifplugin "go.ligato.io/vpp-agent/v3/plugins/linux/ifplugin"
    23  	"go.ligato.io/vpp-agent/v3/plugins/linux/nsplugin"
    24  	"go.ligato.io/vpp-agent/v3/plugins/netalloc"
    25  	"go.ligato.io/vpp-agent/v3/plugins/orchestrator"
    26  	"go.ligato.io/vpp-agent/v3/plugins/vpp/aclplugin"
    27  	"go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin"
    28  	"go.ligato.io/vpp-agent/v3/plugins/vpp/l2plugin"
    29  	"go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin"
    30  )
    31  
    32  // DefaultPlugin is a default instance of Plugin.
    33  var DefaultPlugin = *NewPlugin()
    34  
    35  // NewPlugin creates a new Plugin with the provides Options
    36  func NewPlugin(opts ...Option) *Plugin {
    37  	p := &Plugin{}
    38  
    39  	p.PluginName = "restpapi"
    40  	p.HTTPHandlers = &rest.DefaultPlugin
    41  	p.VPP = &govppmux.DefaultPlugin
    42  	p.ServiceLabel = &servicelabel.DefaultPlugin
    43  	p.AddrAlloc = &netalloc.DefaultPlugin
    44  	p.VPPACLPlugin = &aclplugin.DefaultPlugin
    45  	p.VPPIfPlugin = &ifplugin.DefaultPlugin
    46  	p.VPPL2Plugin = &l2plugin.DefaultPlugin
    47  	p.VPPL3Plugin = &l3plugin.DefaultPlugin
    48  	p.LinuxIfPlugin = &linuxifplugin.DefaultPlugin
    49  	p.NsPlugin = &nsplugin.DefaultPlugin
    50  	p.KVScheduler = &kvscheduler.DefaultPlugin
    51  	p.Dispatcher = &orchestrator.DefaultPlugin
    52  
    53  	for _, o := range opts {
    54  		o(p)
    55  	}
    56  
    57  	p.PluginDeps.Setup()
    58  
    59  	return p
    60  }
    61  
    62  // Option is a function that acts on a Plugin to inject Dependencies or configuration
    63  type Option func(*Plugin)
    64  
    65  // UseDeps returns Option that can inject custom dependencies.
    66  func UseDeps(cb func(*Deps)) Option {
    67  	return func(p *Plugin) {
    68  		cb(&p.Deps)
    69  	}
    70  }