handler

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2020 License: GPL-3.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

View Source
const IterationLimit = 50

IterationLimit is to prevent endless loops.

Variables

This section is empty.

Functions

func GetPluginTypes

func GetPluginTypes() []string

GetPluginTypes returns all registered plugin types.

func NewArgErr

func NewArgErr(key string) error

func RegInitFunc

func RegInitFunc(pluginType string, initFunc NewPluginFunc)

RegInitFunc registers this plugin type. This should only be called in init() of the plugin package. Duplicate plugin types are not allowed.

func RegPlugin

func RegPlugin(c *Config) (err error)

RegPlugin inits and registers this plugin globally. Duplicate plugin tags are not allowed.

func Walk

func Walk(ctx context.Context, qCtx *Context, entryTag string) (err error)

Walk walks through plugins. Walk will return if last plugin.Next() returns a empty tag or any error occurs.

Types

type ArgError

type ArgError struct {
	// contains filtered or unexported fields
}

func (*ArgError) Error

func (err *ArgError) Error() string

type Args

type Args map[string]interface{}

Args contains plugin arguments.

func (Args) Load

func (a Args) Load(key string) (value interface{}, ok bool)

func (Args) LoadBool

func (a Args) LoadBool(key string) (ok bool)

func (Args) LoadInt

func (a Args) LoadInt(key string) (value int, ok bool)

func (Args) LoadSlice

func (a Args) LoadSlice(key string) (s []interface{}, ok bool)

func (Args) LoadString

func (a Args) LoadString(key string) (value string, ok bool)

func (Args) WeakDecode

func (a Args) WeakDecode(output interface{}) error

type Checker

type Checker interface {
	Match(ctx context.Context, qCtx *Context) (matched bool, err error)
}

type Config

type Config struct {
	// Tag, required
	Tag string `yaml:"tag"`

	// Type, required
	Type string `yaml:"type"`

	// Args, might be required by some plugins
	Args Args `yaml:"args"`
}

type Context

type Context struct {
	Q    *dns.Msg
	From net.Addr

	R *dns.Msg
}

func (*Context) Copy

func (ctx *Context) Copy() *Context

func (*Context) String

func (ctx *Context) String() string

type NewPluginFunc

type NewPluginFunc func(c *Config) (p Plugin, err error)

type OneWayPlugin

type OneWayPlugin interface {
	Modify(ctx context.Context, qCtx *Context) (err error)
}

OneWayPlugin only modifies qCtx

type Plugin

type Plugin interface {
	Tag() string
	Type() string

	// Do modifies qCtx and returns next plugin tag.
	Do(ctx context.Context, qCtx *Context) (next string, err error)
}

func GetPlugin

func GetPlugin(tag string) (p Plugin, ok bool)

func NewRedirectPlugin

func NewRedirectPlugin(config *Config, checker Checker, next, redirect string) Plugin

NewRedirectPlugin returns a redirectPlugin. redirectPlugin is a plugin that can redirect qCtx to other plugin under certain condition. It should not modify qCtx. If checker.Match() returns true, the plugin tag from `next` will be returned in redirectPlugin.Do(). Otherwise, `redirect`.

func WrapOneWayPlugin

func WrapOneWayPlugin(config *Config, doPlugin OneWayPlugin, next string) Plugin

WrapOneWayPlugin returns a oneWayPluginWrapper which implements Plugin.

type TagNotDefinedErr

type TagNotDefinedErr struct {
	// contains filtered or unexported fields
}

func NewTagNotDefinedErr

func NewTagNotDefinedErr(tag string) *TagNotDefinedErr

func (*TagNotDefinedErr) Error

func (t *TagNotDefinedErr) Error() string

type TypeNotDefinedErr

type TypeNotDefinedErr struct {
	// contains filtered or unexported fields
}

func NewTypeNotDefinedErr

func NewTypeNotDefinedErr(typ string) *TypeNotDefinedErr

func (*TypeNotDefinedErr) Error

func (t *TypeNotDefinedErr) Error() string

Jump to

Keyboard shortcuts

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