handler

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2020 License: GPL-3.0 Imports: 11 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 defined"
	ETTagNotDefined  = "plugin tag %s not defined"
)
View Source
const (
	// IterationLimit is to prevent endless loops.
	IterationLimit = 50
)

Variables

This section is empty.

Functions

func GetAllPluginTag added in v0.15.0

func GetAllPluginTag() []string

func GetConfigurablePluginTypes added in v0.15.0

func GetConfigurablePluginTypes() []string

GetConfigurablePluginTypes returns all plugin types which are configurable.

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 MustRegPlugin added in v0.14.0

func MustRegPlugin(p Plugin)

MustRegPlugin: see RegPlugin. MustRegPlugin will panic if err.

func NewErrFromTemplate added in v0.12.0

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

func PluginFatalErr added in v0.16.0

func PluginFatalErr(tag string, msg string)

PluginFatalErr: If a plugin has a fatal err, call this.

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 cause an error.

func Walk

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

Walk walks into RouterPlugin. entry must be an RouterPlugin tag. Walk will stop and return when last RouterPlugin.Do() returns: 1. An empty tag. 2. An error.

func WeakDecode added in v0.13.0

func WeakDecode(in map[string]interface{}, output interface{}) error

WeakDecode decodes args from config to output.

Types

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 map[string]interface{} `yaml:"args"`
}

type Context

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

	R *dns.Msg
}

Context is a query context that pass through plugins A Context MUST has a non-nil Q.

func (*Context) Copy

func (ctx *Context) Copy() *Context

func (*Context) String

func (ctx *Context) String() string

type DefaultServerHandler added in v0.15.0

type DefaultServerHandler struct {
	Entry  string
	Logger *logrus.Entry
}

DefaultServerHandler If entry returns an err, a SERVFAIL response will be sent back to client.

func (*DefaultServerHandler) ServeDNS added in v0.15.0

func (h *DefaultServerHandler) ServeDNS(ctx context.Context, qCtx *Context, w ResponseWriter)

ServeDNS: see DefaultServerHandler.

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 DummyServerHandler added in v0.16.0

type DummyServerHandler struct {
	T       *testing.T
	EchoMsg *dns.Msg
	WantErr error
}

func (*DummyServerHandler) ServeDNS added in v0.16.0

func (d *DummyServerHandler) ServeDNS(_ context.Context, qCtx *Context, w ResponseWriter)

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, err error)

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, err error)

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 map[string]interface{}) (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 ResponseWriter added in v0.15.0

type ResponseWriter interface {
	Write(m *dns.Msg) (n int, err error)
}

ResponseWriter can write msg to the client.

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, err error)

type ServerHandler added in v0.15.0

type ServerHandler interface {
	// ServeDNS use ctx to control deadline, exchange qCtx, and write response to w.
	ServeDNS(ctx context.Context, qCtx *Context, w ResponseWriter)
}

Jump to

Keyboard shortcuts

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