Version: v1.8.7 Latest Latest

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

Go to latest
Published: Sep 18, 2021 License: GPL-3.0 Imports: 13 Imported by: 1




View Source
const (
	PITESExecutable = iota


This section is empty.


func DelPlugin added in v0.25.2

func DelPlugin(tag string)

DelPlugin deletes this plugin. If this plugin is a Service, DelPlugin will call Service.Shutdown(). DelPlugin will panic if Service.Shutdown() returns an err.

func GetConfigurablePluginTypes added in v0.15.0

func GetConfigurablePluginTypes() []string

GetConfigurablePluginTypes returns all plugin types which are configurable. This should only be used in testing or debugging.

func InitAndRegPlugin added in v0.10.0

func InitAndRegPlugin(c *Config, errIfDup bool) (err error)

InitAndRegPlugin inits and registers this plugin globally. This is a help func of NewPlugin + RegPlugin.

func MustRegPlugin added in v0.14.0

func MustRegPlugin(p Plugin, errIfDup bool)

MustRegPlugin: see RegPlugin. MustRegPlugin will panic if any err occurred.

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 testing.

func RegInitFunc

func RegInitFunc(pluginType string, initFunc NewPluginFunc, argsType NewArgsFunc)

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

func RegPlugin

func RegPlugin(p Plugin, errIfDup bool) error

RegPlugin registers Plugin p. If errIfDup is true and Plugin.Tag() is duplicated, an err will be returned. If old plugin is a Service, RegPlugin will call Service.Shutdown(). If this failed, RegPlugin will panic.

func WeakDecode added in v0.13.0

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

WeakDecode decodes args from config to output.


type BP added in v0.24.0

type BP struct {
	// contains filtered or unexported fields

BP means basic plugin, which implements Plugin. It also has an internal logger, for convenience.

func NewBP added in v0.24.0

func NewBP(tag string, typ string) *BP

NewBP creates a new BP and initials its logger.

func (*BP) L added in v0.24.0

func (p *BP) L() *zap.Logger

func (*BP) S added in v1.0.0

func (p *BP) S() *zap.SugaredLogger

func (*BP) Tag added in v0.24.0

func (p *BP) Tag() string

func (*BP) Type added in v0.24.0

func (p *BP) Type() string

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"`

Config represents a plugin config

type Context

type Context struct {
	// contains filtered or unexported fields

Context is a query context that pass through plugins A Context will always have a non-nil Q. Context MUST be created by NewContext.

func NewContext added in v0.17.1

func NewContext(q *dns.Msg, from net.Addr) *Context

NewContext creates a new query Context. q is the query dns msg. It cannot be nil, or NewContext will panic. from is the client net.Addr. It can be nil.

func (*Context) Copy

func (ctx *Context) Copy() *Context

Copy deep copies this Context. Note that Copy won't copy registered deferred Executable. To copy them, use CopyDeferFrom after Copy.

func (*Context) CopyDeferFrom added in v0.25.2

func (ctx *Context) CopyDeferFrom(src *Context)

CopyDeferFrom copies defer Executable from src.

func (*Context) CopyNoR added in v1.3.0

func (ctx *Context) CopyNoR() *Context

CopyNoR deep copies this Context. Except deferred Executable and response.

func (*Context) DeferExec added in v0.25.0

func (ctx *Context) DeferExec(e Executable)

DeferExec registers an deferred Executable at this Context.

func (*Context) ExecDefer added in v0.25.0

func (ctx *Context) ExecDefer(cCtx context.Context) error

ExecDefer executes all deferred Executable registered by DeferExec.

func (*Context) From

func (ctx *Context) From() net.Addr

From returns the client net.Addr. It might be nil.

func (*Context) Id added in v0.24.0

func (ctx *Context) Id() uint32

Id returns the Context id. Note: This id is not the dns msg id. It's a unique uint32 growing with the number of query.

func (*Context) InfoField added in v0.24.0

func (ctx *Context) InfoField() zap.Field

InfoField returns a zap.Field. Just for convenience.

func (*Context) IsTCPClient added in v1.3.0

func (ctx *Context) IsTCPClient() bool

func (*Context) Q

func (ctx *Context) Q() *dns.Msg

Q returns the query msg. It always returns a non-nil msg.

func (*Context) R

func (ctx *Context) R() *dns.Msg

R returns the response. It might be nil.

func (*Context) SetResponse added in v0.21.0

func (ctx *Context) SetResponse(r *dns.Msg, status ContextStatus)

SetResponse stores the response r to the context. Note: It just stores the pointer of r. So the caller shouldn't modify or read r after the call.

func (*Context) SetTCPClient added in v1.3.0

func (ctx *Context) SetTCPClient(b bool)

func (*Context) StartTime added in v0.24.0

func (ctx *Context) StartTime() time.Time

StartTime returns the time when the Context was created.

func (*Context) Status added in v0.21.0

func (ctx *Context) Status() ContextStatus

Status returns the context status.

func (*Context) String

func (ctx *Context) String() string

type ContextConnector added in v0.25.0

type ContextConnector interface {
	// Connect connects this ContextPlugin to its predecessor.
	Connect(ctx context.Context, qCtx *Context, pipeCtx *PipeContext) (err error)

ContextConnector can choose when and how to execute its successor.

type ContextPlugin added in v0.19.1

type ContextPlugin interface {

ContextPlugin: See ContextConnector.

type ContextStatus added in v0.21.0

type ContextStatus uint8
const (
	ContextStatusWaitingResponse ContextStatus = iota

func (ContextStatus) String added in v0.21.0

func (status ContextStatus) String() string

type DummyESExecutablePlugin added in v0.25.2

type DummyESExecutablePlugin struct {
	Sleep    time.Duration
	WantR    *dns.Msg
	WantSkip bool
	WantErr  error

func (*DummyESExecutablePlugin) ExecES added in v0.25.2

func (d *DummyESExecutablePlugin) ExecES(_ context.Context, qCtx *Context) (earlyStop bool, err error)

type DummyExecutablePlugin added in v0.24.0

type DummyExecutablePlugin struct {
	Sleep   time.Duration
	WantR   *dns.Msg
	WantErr error

func (*DummyExecutablePlugin) Exec added in v0.24.0

func (d *DummyExecutablePlugin) Exec(_ context.Context, qCtx *Context) (err error)

type DummyMatcherPlugin added in v0.24.0

type DummyMatcherPlugin struct {
	Matched bool
	WantErr error

func (*DummyMatcherPlugin) Match added in v0.24.0

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

type DummyServicePlugin added in v0.24.0

type DummyServicePlugin struct {
	WantShutdownErr error

func (*DummyServicePlugin) Shutdown added in v0.24.0

func (d *DummyServicePlugin) Shutdown() error

type ESExecutable added in v0.25.0

type ESExecutable interface {
	// ExecES: Execute something. earlyStop indicates that it wants
	// to stop the utils.ExecutableCmdSequence ASAP.
	ExecES(ctx context.Context, qCtx *Context) (earlyStop bool, err error)

ESExecutable: Early Stoppable Executable.

type ESExecutablePlugin added in v0.25.0

type ESExecutablePlugin interface {

ESExecutablePlugin: See ESExecutable.

type Executable added in v0.19.1

type Executable interface {
	Exec(ctx context.Context, qCtx *Context) (err error)

Executable can do some cool stuffs.

type ExecutablePlugin added in v0.19.1

type ExecutablePlugin interface {

ExecutablePlugin: See Executable.

type Matcher added in v0.10.0

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

Matcher represents a matcher that can match certain patten in Context.

type MatcherPlugin added in v0.10.0

type MatcherPlugin interface {

MatcherPlugin: See Matcher.

type NewArgsFunc added in v0.24.0

type NewArgsFunc func() interface{}

type NewPluginFunc

type NewPluginFunc func(bp *BP, args interface{}) (p Plugin, err error)

type PipeContext added in v0.17.1

type PipeContext struct {
	// contains filtered or unexported fields

func NewPipeContext added in v0.17.1

func NewPipeContext(s []string, logger *zap.Logger) *PipeContext

func (*PipeContext) ExecNextPlugin added in v0.17.1

func (c *PipeContext) ExecNextPlugin(ctx context.Context, qCtx *Context) error

type Plugin

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

Plugin represents the basic plugin.

func GetPluginAll added in v0.25.2

func GetPluginAll() []Plugin

GetPluginAll returns all registered plugins. This should only be used in testing or debugging.

func NewPlugin added in v0.10.0

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

type PluginError added in v0.25.2

type PluginError struct {
	// contains filtered or unexported fields

func NewPluginError added in v0.19.1

func NewPluginError(tag string, err error) *PluginError

func (*PluginError) Error added in v0.25.2

func (e *PluginError) Error() string

func (*PluginError) Is added in v1.0.0

func (e *PluginError) Is(target error) bool

func (*PluginError) Unwrap added in v0.25.2

func (e *PluginError) Unwrap() error

type PluginInterfaceType added in v0.25.0

type PluginInterfaceType uint8

type PluginWrapper added in v0.25.0

type PluginWrapper struct {
	// contains filtered or unexported fields

PluginWrapper wraps the original plugin to avoid extremely frequently interface conversion. To access the original plugin, use PluginWrapper.GetPlugin() Note: PluginWrapper not implements Executable. It automatically converts Executable to ESExecutable.

func GetPlugin

func GetPlugin(tag string) (p *PluginWrapper, err error)

GetPlugin returns the plugin. If the tag is not registered, an err will be returned. Also see PluginWrapper.

func NewPluginWrapper added in v1.5.0

func NewPluginWrapper(gp Plugin) *PluginWrapper

func (*PluginWrapper) Connect added in v0.25.0

func (w *PluginWrapper) Connect(ctx context.Context, qCtx *Context, pipeCtx *PipeContext) (err error)

func (*PluginWrapper) ExecES added in v0.25.0

func (w *PluginWrapper) ExecES(ctx context.Context, qCtx *Context) (earlyStop bool, err error)

func (*PluginWrapper) GetPlugin added in v0.25.0

func (w *PluginWrapper) GetPlugin() Plugin

func (*PluginWrapper) Is added in v0.25.0

func (*PluginWrapper) Match added in v0.25.0

func (w *PluginWrapper) Match(ctx context.Context, qCtx *Context) (matched bool, err error)

func (*PluginWrapper) Shutdown added in v0.25.2

func (w *PluginWrapper) Shutdown() error

type Service added in v0.24.0

type Service interface {
	// Shutdown and release resources.
	Shutdown() error

Service represents a background service.

type ServicePlugin added in v0.24.0

type ServicePlugin interface {

ServicePlugin: See Service.

Jump to

Keyboard shortcuts

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