coremain

package
v5.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2023 License: GPL-3.0 Imports: 26 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSubCmd

func AddSubCmd(c *cobra.Command)

func DelPluginType

func DelPluginType(typ string)

DelPluginType deletes the init func for this plugin type. It is a noop if pluginType is not registered.

func GetAllPluginTypes

func GetAllPluginTypes() []string

GetAllPluginTypes returns all plugin types which are configurable.

func LoadNewPersetPluginFuncs

func LoadNewPersetPluginFuncs() map[string]NewPersetPluginFunc

func RegNewPersetPluginFunc

func RegNewPersetPluginFunc(tag string, f NewPersetPluginFunc)

func RegNewPluginFunc

func RegNewPluginFunc(typ string, initFunc NewPluginFunc, argsType NewPluginArgsFunc)

RegNewPluginFunc registers the type. If the type has been registered. RegNewPluginFunc will panic.

func Run

func Run() error

Types

type APIConfig

type APIConfig struct {
	HTTP string `yaml:"http"`
}

type BP

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

func NewBP

func NewBP(tag string, m *Mosdns) *BP

NewBP creates a new BP. m MUST NOT nil.

func (*BP) L

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

L returns a non-nil logger.

func (*BP) M

func (p *BP) M() *Mosdns

M returns a non-nil Mosdns.

func (*BP) RegAPI

func (p *BP) RegAPI(mux *chi.Mux)

RegAPI mounts mux to mosdns api. Note: Plugins MUST NOT call RegAPI twice. Since mounting same path to root chi.Mux causes runtime panic.

func (*BP) Tag

func (p *BP) Tag() string

Tag returns the plugin tag. This tag should be unique globally unless it's in a test environment.

type Config

type Config struct {
	Log     mlog.LogConfig `yaml:"log"`
	Include []string       `yaml:"include"`
	Plugins []PluginConfig `yaml:"plugins"`
	API     APIConfig      `yaml:"api"`
}

type Mosdns

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

func NewMosdns

func NewMosdns(cfg *Config) (*Mosdns, error)

NewMosdns initializes a mosdns instance and its plugins.

func NewServer

func NewServer(sf *serverFlags) (*Mosdns, error)

func NewTestMosdnsWithPlugins

func NewTestMosdnsWithPlugins(p map[string]any) *Mosdns

NewTestMosdnsWithPlugins returns a mosdns instance for testing.

func (*Mosdns) CloseWithErr

func (m *Mosdns) CloseWithErr(err error)

CloseWithErr is a shortcut for m.sc.SendCloseSignal

func (*Mosdns) GetAPIRouter

func (m *Mosdns) GetAPIRouter() *chi.Mux

func (*Mosdns) GetMetricsReg

func (m *Mosdns) GetMetricsReg() prometheus.Registerer

GetMetricsReg returns a prometheus.Registerer with a prefix of "mosdns_"

func (*Mosdns) GetPlugin

func (m *Mosdns) GetPlugin(tag string) any

GetPlugin returns a plugin.

func (*Mosdns) GetSafeClose

func (m *Mosdns) GetSafeClose() *safe_close.SafeClose

func (*Mosdns) Logger

func (m *Mosdns) Logger() *zap.Logger

Logger returns a non-nil logger.

func (*Mosdns) RegPluginAPI

func (m *Mosdns) RegPluginAPI(tag string, mux *chi.Mux)

type NewPersetPluginFunc

type NewPersetPluginFunc func(bp *BP) (any, error)

type NewPluginArgsFunc

type NewPluginArgsFunc func() any

NewPluginArgsFunc represents a func that creates a new args object.

type NewPluginFunc

type NewPluginFunc func(bp *BP, args any) (p any, err error)

NewPluginFunc represents a func that can init a Plugin. args is the object created by NewPluginArgsFunc.

type PluginConfig

type PluginConfig struct {
	// Tag for this plugin. Optional. If omitted, this plugin will
	// be registered with a random tag.
	Tag string `yaml:"tag"`

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

	// Args, might be required by some plugins.
	// The type of Args is depended on RegNewPluginFunc.
	// If it's a map[string]any, it will be converted by mapstruct.
	Args any `yaml:"args"`
}

PluginConfig represents a plugin config

type PluginTypeInfo

type PluginTypeInfo struct {
	NewPlugin NewPluginFunc
	NewArgs   NewPluginArgsFunc
}

func GetPluginType

func GetPluginType(typ string) (PluginTypeInfo, bool)

GetPluginType gets the registered type init func.

Jump to

Keyboard shortcuts

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