plugin

package
v0.0.0-...-56286bb Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildHook

type BuildHook interface {
	Hook
	OnBuildPre() error
	OnBuildPost() error
}

type ConfigHook

type ConfigHook interface {
	Hook
	OnConfigLoad(config map[string]interface{}) error
}

type DevHook

type DevHook interface {
	Hook
	OnDevStart() error
	OnDevReload(path string) error
	OnDevStop() error
}

type Hook

type Hook interface {
	Priority() int
}

type HookType

type HookType string
const (
	HookConfig     HookType = "config"
	HookRouter     HookType = "router"
	HookMiddleware HookType = "middleware"
	HookRequest    HookType = "request"
	HookResponse   HookType = "response"
	HookBuild      HookType = "build"
	HookDev        HookType = "dev"
)

type Info

type Info struct {
	Name        string
	Version     string
	Description string
	Enabled     bool
	Config      map[string]interface{}
	Hooks       []HookType
}

type Loader

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

func NewLoader

func NewLoader(registry *Registry, pluginDir string, logger *slog.Logger) *Loader

func (*Loader) Close

func (l *Loader) Close() error

func (*Loader) DiscoverPlugins

func (l *Loader) DiscoverPlugins() ([]string, error)

func (*Loader) LoadFromConfig

func (l *Loader) LoadFromConfig(ctx context.Context, enabled []string, configs map[string]PluginOptions) error

func (*Loader) LoadPlugin

func (l *Loader) LoadPlugin(ctx context.Context, name string, config PluginOptions) error

func (*Loader) LoadedPlugins

func (l *Loader) LoadedPlugins() []string

func (*Loader) UnloadPlugin

func (l *Loader) UnloadPlugin(name string) error

type MiddlewareHook

type MiddlewareHook interface {
	Hook
	OnMiddleware() func(http.Handler) http.Handler
}

type Plugin

type Plugin interface {
	Name() string
	Version() string
	Description() string
	Init(ctx *PluginContext) error
	Close() error
}

type PluginContext

type PluginContext struct {
	Config     map[string]interface{}
	Logger     *slog.Logger
	HTTPClient *http.Client
	Context    context.Context
	// contains filtered or unexported fields
}

func NewPluginContext

func NewPluginContext(ctx context.Context, config map[string]interface{}, logger *slog.Logger) *PluginContext

func (*PluginContext) ConfigBool

func (p *PluginContext) ConfigBool(key string) bool

func (*PluginContext) ConfigInt

func (p *PluginContext) ConfigInt(key string) int

func (*PluginContext) ConfigString

func (p *PluginContext) ConfigString(key string) string

func (*PluginContext) ConfigStringSlice

func (p *PluginContext) ConfigStringSlice(key string) []string

func (*PluginContext) Get

func (p *PluginContext) Get(key string) (interface{}, bool)

func (*PluginContext) GetBool

func (p *PluginContext) GetBool(key string) (bool, bool)

func (*PluginContext) GetInt

func (p *PluginContext) GetInt(key string) (int, bool)

func (*PluginContext) GetString

func (p *PluginContext) GetString(key string) (string, bool)

func (*PluginContext) GetStringSlice

func (p *PluginContext) GetStringSlice(key string) ([]string, bool)

func (*PluginContext) Set

func (p *PluginContext) Set(key string, value interface{})

type PluginOptions

type PluginOptions map[string]interface{}

type Registry

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

func NewRegistry

func NewRegistry(logger *slog.Logger) *Registry

func (*Registry) All

func (r *Registry) All() []Plugin

func (*Registry) AllInfo

func (r *Registry) AllInfo() []*Info

func (*Registry) CloseAll

func (r *Registry) CloseAll() error

func (*Registry) Count

func (r *Registry) Count() int

func (*Registry) Get

func (r *Registry) Get(name string) (Plugin, bool)

func (*Registry) GetConfig

func (r *Registry) GetConfig(name string) map[string]interface{}

func (*Registry) GetHooks

func (r *Registry) GetHooks(hookType HookType) []interface{}

func (*Registry) Info

func (r *Registry) Info(name string) (*Info, bool)

func (*Registry) Names

func (r *Registry) Names() []string

func (*Registry) Register

func (r *Registry) Register(p Plugin) error

func (*Registry) SetConfig

func (r *Registry) SetConfig(name string, config map[string]interface{})

func (*Registry) Unregister

func (r *Registry) Unregister(name string) error

type RequestHook

type RequestHook interface {
	Hook
	OnRequest(r *http.Request) error
}

type ResponseHook

type ResponseHook interface {
	Hook
	OnResponse(w http.ResponseWriter, r *http.Request, status int)
}

type Router

type Router interface {
	Get(pattern string, handler http.HandlerFunc)
	Post(pattern string, handler http.HandlerFunc)
	Put(pattern string, handler http.HandlerFunc)
	Delete(pattern string, handler http.HandlerFunc)
	Use(middleware func(http.Handler) http.Handler)
	Mount(pattern string, handler http.Handler)
}

type RouterHook

type RouterHook interface {
	Hook
	OnRouterInit(router Router) error
}

Jump to

Keyboard shortcuts

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