plugin

package
v0.0.0-...-32ff608 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2023 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Overview

Package plugin implements a general plugin factory system which provides plugin registration and loading. It is mainly used when certain plugins must be loaded by configuration. This system is not supposed to register plugins that do not rely on configuration like codec. Instead, plugins that do not rely on configuration should be registered by calling methods in certain packages.

Index

Constants

This section is empty.

Variables

View Source
var (
	// SetupTimeout is the timeout for initialization of each plugin.
	// Modify it if some plugins' initialization does take a long time.
	SetupTimeout = 10 * time.Second

	// MaxPluginSize is the max number of plugins.
	MaxPluginSize = 1000
)
View Source
var (
	Connector = "connector"
	Registry  = "registry"
	Protocol  = "protocol"
)

indicates all plugin type

View Source
var (
	NacosRegistry = "nacos"
	ETCDRegistry  = "etcd"
)

indicates registry name list

View Source
var Name = "name"

name for every plugin

View Source
var (
	Standalone = "standalone"
)

indicates connector name list

Functions

func Register

func Register(name string, f Plugin)

Register registers a plugin factory. Name of the plugin should be specified. It is supported to register instances which are the same implementation of plugin Plugin but use different configuration.

func SetActivePlugin

func SetActivePlugin(ap map[string]string)

Types

type Config

type Config map[string]map[string]yaml.Node

Config is the configuration of all plugins. plugin type => { plugin name => plugin config }

func (Config) Setup

func (c Config) Setup() error

Setup loads plugins by configuration.

type Decoder

type Decoder interface {
	Decode(cfg interface{}) error // the input param is the custom configuration of the plugin
}

Decoder is the interface used to decode plugin configuration.

type Plugin

type Plugin interface {
	// Type returns type of the plugin, i.e. selector, log, config, tracing.
	Type() string
	// Setup loads plugin by configuration.
	// The data structure of the configuration of the plugin needs to be defined in advance。
	Setup(name string, dec Decoder) error
}

Plugin is the interface for plugin factory abstraction. Custom Plugins need to implement this interface to be registered as a plugin with certain type.

func Get

func Get(typ string, name string) Plugin

Get returns a plugin Plugin by its type and name.

func GetByType

func GetByType(typ string) Plugin

GetByType return the single plugin

type YamlNodeDecoder

type YamlNodeDecoder struct {
	Node *yaml.Node
}

YamlNodeDecoder is a decoder for a yaml.Node of the yaml config file.

func (*YamlNodeDecoder) Decode

func (d *YamlNodeDecoder) Decode(cfg interface{}) error

Decode decodes a yaml.Node of the yaml config file.

Directories

Path Synopsis
rocketmq/mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
database
nacos/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL