Documentation ¶
Index ¶
- Constants
- func DelPlugin(tag string)
- func ExecChainNode(ctx context.Context, qCtx *Context, n ExecutableChainNode) error
- func GetConfigurablePluginTypes() []string
- func InitAndRegPlugin(c *Config, errIfDup bool) (err error)
- func MustRegPlugin(p Plugin, errIfDup bool)
- func PluginFatalErr(tag string, msg string)
- func PurgePluginRegister()
- func RegInitFunc(pluginType string, initFunc NewPluginFunc, argsType NewArgsFunc)
- func RegPlugin(p Plugin, errIfDup bool) error
- func WeakDecode(in map[string]interface{}, output interface{}) error
- type BP
- type Config
- type Context
- func (ctx *Context) Copy() *Context
- func (ctx *Context) CopyTo(d *Context) *Context
- func (ctx *Context) From() net.Addr
- func (ctx *Context) Id() uint32
- func (ctx *Context) InfoField() zap.Field
- func (ctx *Context) OriginalQuery() *dns.Msg
- func (ctx *Context) Q() *dns.Msg
- func (ctx *Context) R() *dns.Msg
- func (ctx *Context) SetResponse(r *dns.Msg, status ContextStatus)
- func (ctx *Context) StartTime() time.Time
- func (ctx *Context) Status() ContextStatus
- func (ctx *Context) String() string
- type ContextStatus
- type DummyExecutablePlugin
- type DummyMatcherPlugin
- type DummyServicePlugin
- type Executable
- type ExecutableChainNode
- type ExecutableNodeWrapper
- type ExecutablePlugin
- type LinkedListNode
- type Matcher
- type MatcherPlugin
- type NewArgsFunc
- type NewPluginFunc
- type NodeLinker
- type Plugin
- type PluginError
- type PluginInterfaceType
- type PluginWrapper
- func (w *PluginWrapper) Exec(ctx context.Context, qCtx *Context, next ExecutableChainNode) error
- func (w *PluginWrapper) GetPlugin() Plugin
- func (w *PluginWrapper) Is(t PluginInterfaceType) bool
- func (w *PluginWrapper) Match(ctx context.Context, qCtx *Context) (matched bool, err error)
- func (w *PluginWrapper) Shutdown() error
- type Service
- type ServicePlugin
Constants ¶
const ( PITESExecutable = iota PITMatcher PITService )
Variables ¶
This section is empty.
Functions ¶
func DelPlugin ¶
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 ExecChainNode ¶
func ExecChainNode(ctx context.Context, qCtx *Context, n ExecutableChainNode) error
func GetConfigurablePluginTypes ¶
func GetConfigurablePluginTypes() []string
GetConfigurablePluginTypes returns all plugin types which are configurable. This should only be used in testing or debugging.
func InitAndRegPlugin ¶
InitAndRegPlugin inits and registers this plugin globally. This is a help func of NewPlugin + RegPlugin.
func MustRegPlugin ¶
MustRegPlugin: see RegPlugin. MustRegPlugin will panic if any err occurred.
func PluginFatalErr ¶
PluginFatalErr: If a plugin has a fatal err, call this.
func PurgePluginRegister ¶
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 ¶
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 ¶
WeakDecode decodes args from config to output.
Types ¶
type BP ¶
type BP struct {
// contains filtered or unexported fields
}
BP represents a basic plugin, which implements Plugin. It also has an internal logger, for convenience.
func (*BP) S ¶
func (p *BP) S() *zap.SugaredLogger
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 ¶
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) Id ¶
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) OriginalQuery ¶ added in v2.2.1
OriginalQuery returns the copied original query msg a that created the Context. It always returns a non-nil msg. The returned msg SHOULD NOT be modified.
func (*Context) SetResponse ¶
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) Status ¶
func (ctx *Context) Status() ContextStatus
Status returns the context status.
type ContextStatus ¶
type ContextStatus uint8
const ( ContextStatusWaitingResponse ContextStatus = iota ContextStatusResponded ContextStatusServerFailed ContextStatusDropped ContextStatusRejected )
func (ContextStatus) String ¶
func (status ContextStatus) String() string
type DummyExecutablePlugin ¶
type DummyExecutablePlugin struct { *BP WantSkip bool WantSleep time.Duration WantR *dns.Msg WantErr error }
func (*DummyExecutablePlugin) Exec ¶
func (d *DummyExecutablePlugin) Exec(ctx context.Context, qCtx *Context, next ExecutableChainNode) error
type DummyMatcherPlugin ¶
type DummyServicePlugin ¶
func (*DummyServicePlugin) Shutdown ¶
func (d *DummyServicePlugin) Shutdown() error
type Executable ¶
type Executable interface {
Exec(ctx context.Context, qCtx *Context, next ExecutableChainNode) error
}
Executable represents something that is executable.
type ExecutableChainNode ¶
type ExecutableChainNode interface { Executable LinkedListNode }
ExecutableChainNode represents a node in a executable chain.
func FirstNode ¶
func FirstNode(n ExecutableChainNode) ExecutableChainNode
FirstNode returns the first node of chain of n.
func LastNode ¶ added in v2.2.0
func LastNode(n ExecutableChainNode) ExecutableChainNode
LastNode returns the Latest node of chain of n.
func WrapExecutable ¶
func WrapExecutable(e Executable) ExecutableChainNode
WrapExecutable wraps a Executable to a ExecutableChainNode.
type ExecutableNodeWrapper ¶
type ExecutableNodeWrapper struct { Executable NodeLinker }
ExecutableNodeWrapper wraps a Executable to a ExecutableChainNode.
type ExecutablePlugin ¶
type ExecutablePlugin interface { Plugin Executable }
ExecutablePlugin represents a Plugin that is Executable.
type LinkedListNode ¶
type LinkedListNode interface { Previous() ExecutableChainNode Next() ExecutableChainNode LinkPrevious(n ExecutableChainNode) LinkNext(n ExecutableChainNode) }
type MatcherPlugin ¶
MatcherPlugin represents a Plugin that is a Matcher.
type NewArgsFunc ¶
type NewArgsFunc func() interface{}
NewArgsFunc represents a func that creates a new args object.
type NewPluginFunc ¶
NewPluginFunc represents a func that can init a Plugin. args is the object created by NewArgsFunc.
type NodeLinker ¶
type NodeLinker struct {
// contains filtered or unexported fields
}
NodeLinker implements LinkedListNode.
func (*NodeLinker) LinkNext ¶
func (l *NodeLinker) LinkNext(n ExecutableChainNode)
func (*NodeLinker) LinkPrevious ¶
func (l *NodeLinker) LinkPrevious(n ExecutableChainNode)
func (*NodeLinker) Next ¶
func (l *NodeLinker) Next() ExecutableChainNode
func (*NodeLinker) Previous ¶
func (l *NodeLinker) Previous() ExecutableChainNode
type Plugin ¶
Plugin represents the basic plugin.
func GetPluginAll ¶
func GetPluginAll() []Plugin
GetPluginAll returns all registered plugins. This should only be used in testing or debugging.
type PluginError ¶
type PluginError struct {
// contains filtered or unexported fields
}
func NewPluginError ¶
func NewPluginError(tag string, err error) *PluginError
func (*PluginError) Error ¶
func (e *PluginError) Error() string
func (*PluginError) Is ¶
func (e *PluginError) Is(target error) bool
func (*PluginError) Unwrap ¶
func (e *PluginError) Unwrap() error
type PluginInterfaceType ¶
type PluginInterfaceType uint8
type PluginWrapper ¶
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 ¶
func NewPluginWrapper(gp Plugin) *PluginWrapper
func (*PluginWrapper) Exec ¶
func (w *PluginWrapper) Exec(ctx context.Context, qCtx *Context, next ExecutableChainNode) error
func (*PluginWrapper) GetPlugin ¶
func (w *PluginWrapper) GetPlugin() Plugin
func (*PluginWrapper) Is ¶
func (w *PluginWrapper) Is(t PluginInterfaceType) bool
func (*PluginWrapper) Shutdown ¶
func (w *PluginWrapper) Shutdown() error
type Service ¶
type Service interface { // Shutdown and release resources. Shutdown() error }
Service represents a background service.
type ServicePlugin ¶
ServicePlugin represents a Plugin that is a Service.