plugins

package
v2.0.3-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StorageDriverPlugin the storage driver plugin type.
	StorageDriverPlugin = PluginType("storagedriver")
	// StorageManagerPlugin the storage manager plugin type
	StorageManagerPlugin = PluginType("storagemanager")
)

Variables

PluginTypes explicitly stores all available plugin types.

Functions

func Initialize

func Initialize(plugins map[PluginType][]*PluginProperties) error

Initialize builds all plugins defined in config file.

func RegisterPluginBuilder

func RegisterPluginBuilder(pt PluginType, name string, builder Builder) error

RegisterPluginBuilder register a plugin builder that will be called to create a new plugin instant when cdn starts.

Types

type Builder

type Builder func(conf interface{}) (Plugin, error)

Builder is a function that creates a new plugin instant with the giving conf.

type Manager

type Manager interface {
	// AddBuilder adds a Builder object with the giving plugin type and name.
	AddBuilder(pt PluginType, name string, b Builder) error

	// GetBuilder returns a Builder object with the giving plugin type and name.
	GetBuilder(pt PluginType, name string) (Builder, bool)

	// DeleteBuilder deletes a builder with the giving plugin type and name.
	DeleteBuilder(pt PluginType, name string)

	// AddPlugin adds a plugin into this manager.
	AddPlugin(p Plugin) error

	// GetPlugin returns a plugin with the giving plugin type and name.
	GetPlugin(pt PluginType, name string) (Plugin, bool)

	// DeletePlugin deletes a plugin with the giving plugin type and name.
	DeletePlugin(pt PluginType, name string)
}

Manager manages all plugin builders and plugin instants.

func NewManager

func NewManager() Manager

NewManager creates a default plugin manager instant.

type Plugin

type Plugin interface {
	// Type returns the type of this plugin.
	Type() PluginType

	// Name returns the name of this plugin.
	Name() string
}

Plugin defines methods that plugins need to implement.

func GetPlugin

func GetPlugin(pt PluginType, name string) (Plugin, bool)

GetPlugin returns a plugin instant with the giving plugin type and name.

type PluginProperties

type PluginProperties struct {
	Name   string      `yaml:"name" mapstructure:"name"`
	Enable bool        `yaml:"enable" mapstructure:"enable"`
	Config interface{} `yaml:"config" mapstructure:"config"`
}

PluginProperties the properties of a plugin.

type PluginType

type PluginType string

PluginType defines the type of plugin.

type Repository

type Repository interface {
	// Add adds a data to this repository.
	Add(pt PluginType, name string, data interface{}) error

	// Get gets a data with the giving type and name from this
	// repository.
	Get(pt PluginType, name string) (interface{}, bool)

	// Delete deletes a data with the giving type and name from
	// this repository.
	Delete(pt PluginType, name string)
}

Repository stores data related to plugin.

func NewRepository

func NewRepository() Repository

NewRepository creates a default repository instant.

Jump to

Keyboard shortcuts

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