plugins

package
v0.0.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(cons *Constructor)

Register registers a filter kind.

func SystemConstructors

func SystemConstructors() map[string]*Constructor

SystemConstructors returns all system plugins.

Types

type AgentHandler

type AgentHandler interface {
	// If the plugin doesn't handle the request, it should return false.
	HandleAgentRequest(w http.ResponseWriter, r *http.Request) bool
}

AgentHandler is the handler to handle requests from agent port (default 9900).

type BaseSpec

type BaseSpec struct {
	NameField string `json:"name"`
	KindField string `json:"kind"`
}

BaseSpec is the base spec for all plugins.

func (BaseSpec) Kind

func (s BaseSpec) Kind() string

Kind returns kind.

func (BaseSpec) Name

func (s BaseSpec) Name() string

Name returns name.

type Constructor

type Constructor struct {
	// Kind is the kind of the plugin.
	Kind string

	// DefaultSpec returns a default spec for the plugin, with default values.
	// The function should always return a new spec copy, since it will be
	// modified and used by next moves.
	//
	// NOTE1: The DefaultSpec must returns complete spec (including name) for system plugins.
	DefaultSpec func() Spec

	// SystemPlugin being true value indicates the plugin is system-level,
	// which means it will always be loaded even if not specified in the config.
	SystemPlugin bool

	// NewInstance creates a new plugin instance for the kind.
	// NOTE: The spec has the same type with the one which DefaultSpec returns.
	NewInstance func(spec Spec) (Plugin, error)
}

Constructor contains metadata and contruction resources of a kind of plugin.

type ConstructorsByKind

type ConstructorsByKind []*Constructor

ConstructorsByKind is a slice of Constructor, which is sortable by Kind.

func (ConstructorsByKind) Len

func (c ConstructorsByKind) Len() int

func (ConstructorsByKind) Less

func (c ConstructorsByKind) Less(i, j int) bool

func (ConstructorsByKind) Swap

func (c ConstructorsByKind) Swap(i, j int)

type HTTPDoer

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPDoer is the interface to do HTTP request.

type Plugin

type Plugin interface {
	Close() error
	Name() string
}

Plugin is the plugin interface.

func New

func New(spec Spec) (Plugin, error)

New creates a plugin instance according to the spec.

func NewFromJSON

func NewFromJSON(specJSON []byte) (Plugin, error)

NewFromJSON creates a plugin instance according to the JSON spec.

type Spec

type Spec interface {
	// Name returns name.
	Name() string

	// Kind returns kind.
	Kind() string

	// Validate validates the spec.
	Validate() error
}

Spec is the common interface of filter specs

type UserClientRequestWrapper

type UserClientRequestWrapper interface {
	WrapUserClientRequest(parent context.Context, req *http.Request) *http.Request
}

UserClientRequestWrapper wraps the user client.

type UserClientWrapper

type UserClientWrapper interface {
	WrapUserClient(client HTTPDoer) HTTPDoer
}

UserClientWrapper wraps the user client.

type UserHandlerFuncWrapper

type UserHandlerFuncWrapper interface {
	// If the plugin doesn't wrap the user handler, it should not implement this method.
	WrapUserHandlerFunc(fn http.HandlerFunc) http.HandlerFunc
}

UserHandlerFuncWrapper wraps the user HandleFunc.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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