Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
87 lines (75 sloc) 2.35 KB
// Copyright (c) 2019 Cisco and/or its affiliates.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
// Package infra provides Plugin interface and related utilities.
package infra
import (
// Plugin interface defines plugin's basic life-cycle methods.
type Plugin interface {
// Init is called in the agent`s startup phase.
Init() error
// Close is called in the agent`s cleanup phase.
Close() error
// String returns unique name of the plugin.
String() string
// PostInit interface defines an optional method for plugins with additional initialization.
type PostInit interface {
// AfterInit is called once Init() of all plugins have returned without error.
AfterInit() error
// PluginName is a part of the plugin's API.
// It's used by embedding it into Plugin to
// provide unique name of the plugin.
type PluginName string
// String returns the PluginName.
func (name PluginName) String() string {
return string(name)
// SetName sets plugin name.
func (name *PluginName) SetName(n string) {
*name = PluginName(n)
// PluginDeps defines common dependencies for use with plugins.
// It can easily be embedded in Deps for Plugin:
// type Deps struct {
// infra.PluginDeps
// // other dependencies
// }
type PluginDeps struct {
Log logging.PluginLogger
Cfg config.PluginConfig
// SetupLog sets up default instance for plugin log dep.
func (d *PluginDeps) SetupLog() {
if d.Log == nil {
d.Log = logging.ForPlugin(d.String())
// Setup sets up default instances for plugin deps.
func (d *PluginDeps) Setup() {
if d.Cfg == nil {
d.Cfg = config.ForPlugin(d.String())
// Close is an empty implementation used to avoid need for
// implementing it by plugins that do not need it.
func (d *PluginDeps) Close() error {
return nil
You can’t perform that action at this time.