handler

package
v0.12.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ETInvalidArgs    = "invalid args: %w"
	ETPluginErr      = "plugin %s reported an err: %w"
	ETTypeNotDefined = "plugin type %s not not defined"
	ETTagNotDefined  = "plugin tag %s not not defined"
)
View Source
const (
	// IterationLimit is to prevent endless loops.
	IterationLimit = 50

	// StopSignTag: See Walk().
	StopSignTag = "end"
)

Variables

This section is empty.

Functions

func GetPluginTypes

func GetPluginTypes() []string

GetPluginTypes returns all registered plugin types.

func InitAndRegPlugin added in v0.10.0

func InitAndRegPlugin(c *Config) (err error)

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

func NewErrFromTemplate added in v0.12.0

func NewErrFromTemplate(t ErrTemplate, args ...interface{}) error

func PurgePluginRegister added in v0.12.0

func PurgePluginRegister()

PurgePluginRegister should only be used in test.

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(p Plugin) error

RegPlugin registers this Plugin globally. Duplicate Plugin tag will be overwritten. Plugin must be a FunctionalPlugin, MatcherPlugin or RouterPlugin.

func Walk

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

Walk walks into this RouterPlugin. Walk will stop and return when last RouterPlugin.Do() returns: 1. An empty tag or StopSignTag. 2. An error.

Types

type Args

type Args map[string]interface{}

Args contains plugin arguments.

func (Args) WeakDecode

func (a Args) WeakDecode(output interface{}) 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) Logf added in v0.12.0

func (ctx *Context) Logf(level logrus.Level, format string, args ...interface{})

func (*Context) String

func (ctx *Context) String() string

type DummyFunctional added in v0.10.0

type DummyFunctional struct {
	WantErr error
}

func (*DummyFunctional) Do added in v0.10.0

func (d *DummyFunctional) Do(_ context.Context, _ *Context) (err error)

type DummyMatcher added in v0.10.0

type DummyMatcher struct {
	Matched bool
	WantErr error
}

func (*DummyMatcher) Match added in v0.10.0

func (d *DummyMatcher) Match(_ context.Context, _ *Context) (matched bool, err error)

type DummyRouterPlugin added in v0.12.0

type DummyRouterPlugin struct {
	TagStr   string
	WantNext string
	WantErr  error
}

func (*DummyRouterPlugin) Do added in v0.12.0

func (d *DummyRouterPlugin) Do(_ context.Context, _ *Context) (next string, err error)

func (*DummyRouterPlugin) Tag added in v0.12.0

func (d *DummyRouterPlugin) Tag() string

func (*DummyRouterPlugin) Type added in v0.12.0

func (d *DummyRouterPlugin) Type() string

type ErrTemplate added in v0.12.0

type ErrTemplate string

type Error added in v0.12.0

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

func (*Error) Error added in v0.12.0

func (e *Error) Error() string

type Functional added in v0.10.0

type Functional interface {
	Do(ctx context.Context, qCtx *Context) (err error)
}

type FunctionalPlugin added in v0.10.0

type FunctionalPlugin interface {
	Plugin
	Functional
}

func GetFunctionalPlugin added in v0.10.0

func GetFunctionalPlugin(tag string) (p FunctionalPlugin, ok bool)

type FunctionalPluginWrapper added in v0.10.0

type FunctionalPluginWrapper struct {
	Functional
	// contains filtered or unexported fields
}

func WrapFunctionalPlugin added in v0.10.0

func WrapFunctionalPlugin(tag, typ string, functional Functional) *FunctionalPluginWrapper

WrapFunctionalPlugin returns a *FunctionalPluginWrapper which implements Plugin and FunctionalPlugin.

func (*FunctionalPluginWrapper) Tag added in v0.10.0

func (*FunctionalPluginWrapper) Type added in v0.10.0

func (p *FunctionalPluginWrapper) Type() string

type Matcher added in v0.10.0

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

type MatcherPlugin added in v0.10.0

type MatcherPlugin interface {
	Plugin
	Matcher
}

func GetMatcherPlugin added in v0.10.0

func GetMatcherPlugin(tag string) (p MatcherPlugin, ok bool)

type MatcherPluginWrapper added in v0.10.0

type MatcherPluginWrapper struct {
	Matcher
	// contains filtered or unexported fields
}

func WrapMatcherPlugin added in v0.10.0

func WrapMatcherPlugin(tag, typ string, matcher Matcher) *MatcherPluginWrapper

WrapMatcherPlugin returns a *MatcherPluginWrapper which implements Plugin and MatcherPlugin.

func (*MatcherPluginWrapper) Tag added in v0.10.0

func (c *MatcherPluginWrapper) Tag() string

func (*MatcherPluginWrapper) Type added in v0.10.0

func (c *MatcherPluginWrapper) Type() string

type NewPluginFunc

type NewPluginFunc func(tag string, args Args) (p Plugin, err error)

type Plugin

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

func GetPlugin

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

func NewPlugin added in v0.10.0

func NewPlugin(c *Config) (p Plugin, err error)

type RouterPlugin added in v0.10.0

type RouterPlugin interface {
	Plugin
	Do(ctx context.Context, qCtx *Context) (next string, err error)
}

func GetRouterPlugin added in v0.10.0

func GetRouterPlugin(tag string) (p RouterPlugin, ok bool)

Jump to

Keyboard shortcuts

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