Documentation
¶
Overview ¶
Package plugin provides a flexible plugin system for extending Buffalo functionality.
Index ¶
- type CompilerPlugin
- type Config
- type HookPlugin
- type HookPoint
- type Input
- type Loader
- type Metadata
- type Output
- type Plugin
- type PluginType
- type RegisteredPlugin
- type Registry
- func (r *Registry) ExecuteCompiler(ctx context.Context, language string, input *Input) (*Output, error)
- func (r *Registry) ExecuteHook(ctx context.Context, hookPoint HookPoint, input *Input) error
- func (r *Registry) Get(name string) (*RegisteredPlugin, error)
- func (r *Registry) InitAll() error
- func (r *Registry) List() []*RegisteredPlugin
- func (r *Registry) ListByType(pluginType PluginType) []*RegisteredPlugin
- func (r *Registry) Register(plugin Plugin, config Config) error
- func (r *Registry) ShutdownAll() error
- func (r *Registry) Unregister(name string) error
- type SimpleNamingValidator
- func (v *SimpleNamingValidator) Description() string
- func (v *SimpleNamingValidator) Execute(ctx context.Context, input *Input) (*Output, error)
- func (v *SimpleNamingValidator) Init(config Config) error
- func (v *SimpleNamingValidator) Name() string
- func (v *SimpleNamingValidator) Shutdown() error
- func (v *SimpleNamingValidator) Type() PluginType
- func (v *SimpleNamingValidator) Version() string
- type Status
- type TransformerPlugin
- type ValidatorPlugin
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompilerPlugin ¶
type CompilerPlugin interface {
Plugin
// SupportedLanguage returns the language this compiler supports
SupportedLanguage() string
// RequiredTools returns external tools needed (e.g., "protoc-gen-ts")
RequiredTools() []string
// ValidateEnvironment checks if required tools are available
ValidateEnvironment() error
}
CompilerPlugin extends Plugin for language compilers
type Config ¶
type Config struct {
// Name is the plugin name
Name string
// Enabled indicates if the plugin is active
Enabled bool
// HookPoints defines when the plugin should run
HookPoints []HookPoint
// Options contains plugin-specific configuration as key-value pairs
Options map[string]interface{}
// Priority defines execution order (higher = earlier, default = 100)
Priority int
}
Config contains plugin configuration
type HookPlugin ¶
type HookPlugin interface {
Plugin
// CanModifyFiles indicates if this hook can modify files
CanModifyFiles() bool
}
HookPlugin extends Plugin for lifecycle hooks
type HookPoint ¶
type HookPoint string
HookPoint defines when a plugin hook should be executed
const ( // HookPointPreBuild runs before any build operations HookPointPreBuild HookPoint = "pre-build" // HookPointPostParse runs after proto files are parsed HookPointPostParse HookPoint = "post-parse" // HookPointPreCompile runs before compilation of each language HookPointPreCompile HookPoint = "pre-compile" // HookPointPostCompile runs after compilation of each language HookPointPostCompile HookPoint = "post-compile" // HookPointPostBuild runs after all build operations complete HookPointPostBuild HookPoint = "post-build" )
type Input ¶
type Input struct {
// ProtoFiles are the proto file paths being processed
ProtoFiles []string
// OutputDir is the base output directory
OutputDir string
// Language is the target language (for compiler plugins)
Language string
// ImportPaths are the proto import paths
ImportPaths []string
// GeneratedFiles are files generated by previous stages
GeneratedFiles []string
// Metadata contains additional context information
Metadata map[string]interface{}
// WorkingDir is the current working directory
WorkingDir string
}
Input contains data passed to a plugin during execution
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader handles loading plugins from filesystem
func (*Loader) GetLoadedPlugins ¶
GetLoadedPlugins returns names of all loaded plugins
func (*Loader) LoadByName ¶
LoadByName loads a specific plugin by name from configured directories
type Metadata ¶
type Metadata struct {
// Name is the plugin name
Name string `json:"name"`
// Version is the semantic version
Version string `json:"version"`
// Type is the plugin type
Type PluginType `json:"type"`
// Description is a human-readable description
Description string `json:"description"`
// Author is the plugin author/maintainer
Author string `json:"author"`
// Homepage is the plugin's website or repository
Homepage string `json:"homepage"`
// License is the plugin's license
License string `json:"license"`
// Tags are searchable tags
Tags []string `json:"tags"`
// RequiredBuffaloVersion is the minimum Buffalo version required
RequiredBuffaloVersion string `json:"required_buffalo_version"`
}
Metadata contains plugin metadata for discovery and display
type Output ¶
type Output struct {
// Success indicates if the plugin executed successfully
Success bool
// GeneratedFiles are new files created by the plugin
GeneratedFiles []string
// ModifiedFiles are existing files modified by the plugin
ModifiedFiles []string
// Messages are informational messages from the plugin
Messages []string
// Warnings are non-fatal issues encountered
Warnings []string
// Errors are fatal errors that occurred
Errors []string
// Metadata contains additional output data
Metadata map[string]interface{}
}
Output contains the result of plugin execution
type Plugin ¶
type Plugin interface {
// Name returns the unique name of the plugin
Name() string
// Version returns the semantic version of the plugin
Version() string
// Type returns the plugin type
Type() PluginType
// Description returns a human-readable description
Description() string
// Init initializes the plugin with configuration
Init(config Config) error
// Execute runs the plugin logic
Execute(ctx context.Context, input *Input) (*Output, error)
// Shutdown performs cleanup when the plugin is unloaded
Shutdown() error
}
Plugin is the main interface that all plugins must implement
func NewSimpleNamingValidator ¶
func NewSimpleNamingValidator() Plugin
NewSimpleNamingValidator creates a new built-in naming validator
type PluginType ¶
type PluginType string
PluginType defines the type of plugin
const ( // PluginTypeCompiler adds support for new programming languages PluginTypeCompiler PluginType = "compiler" // PluginTypeValidator validates proto files and generated code PluginTypeValidator PluginType = "validator" // PluginTypeTransformer transforms/post-processes generated code PluginTypeTransformer PluginType = "transformer" // PluginTypeHook executes custom logic at specific build stages PluginTypeHook PluginType = "hook" // PluginTypeGenerator generates additional artifacts (docs, configs, etc) PluginTypeGenerator PluginType = "generator" )
type RegisteredPlugin ¶
type RegisteredPlugin struct {
Plugin Plugin
Config Config
Metadata Metadata
Status Status
// contains filtered or unexported fields
}
RegisteredPlugin wraps a plugin with metadata and state
func (*RegisteredPlugin) GetStatus ¶
func (rp *RegisteredPlugin) GetStatus() Status
GetStatus safely retrieves the plugin status
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages plugin registration, lifecycle, and execution
func NewRegistry ¶
NewRegistry creates a new plugin registry
func (*Registry) ExecuteCompiler ¶
func (r *Registry) ExecuteCompiler(ctx context.Context, language string, input *Input) (*Output, error)
ExecuteCompiler executes a compiler plugin for a specific language
func (*Registry) ExecuteHook ¶
ExecuteHook executes all plugins registered for a specific hook point
func (*Registry) Get ¶
func (r *Registry) Get(name string) (*RegisteredPlugin, error)
Get retrieves a registered plugin by name
func (*Registry) List ¶
func (r *Registry) List() []*RegisteredPlugin
List returns all registered plugins
func (*Registry) ListByType ¶
func (r *Registry) ListByType(pluginType PluginType) []*RegisteredPlugin
ListByType returns plugins of a specific type
func (*Registry) ShutdownAll ¶
ShutdownAll shuts down all plugins
func (*Registry) Unregister ¶
Unregister removes a plugin from the registry
type SimpleNamingValidator ¶
type SimpleNamingValidator struct {
// contains filtered or unexported fields
}
SimpleNamingValidator is a built-in validator for testing It validates proto file naming without requiring external plugins
func (*SimpleNamingValidator) Description ¶
func (v *SimpleNamingValidator) Description() string
func (*SimpleNamingValidator) Init ¶
func (v *SimpleNamingValidator) Init(config Config) error
func (*SimpleNamingValidator) Name ¶
func (v *SimpleNamingValidator) Name() string
func (*SimpleNamingValidator) Shutdown ¶
func (v *SimpleNamingValidator) Shutdown() error
func (*SimpleNamingValidator) Type ¶
func (v *SimpleNamingValidator) Type() PluginType
func (*SimpleNamingValidator) Version ¶
func (v *SimpleNamingValidator) Version() string
type Status ¶
type Status string
Status represents the current state of a plugin
const ( // StatusLoaded means the plugin is loaded but not initialized StatusLoaded Status = "loaded" // StatusInitialized means the plugin is initialized and ready StatusInitialized Status = "initialized" // StatusRunning means the plugin is currently executing StatusRunning Status = "running" // StatusError means the plugin encountered an error StatusError Status = "error" // StatusDisabled means the plugin is disabled StatusDisabled Status = "disabled" )
type TransformerPlugin ¶
type TransformerPlugin interface {
Plugin
// SupportedFileTypes returns file extensions this transformer handles
SupportedFileTypes() []string
}
TransformerPlugin extends Plugin for code transformers
type ValidatorPlugin ¶
type ValidatorPlugin interface {
Plugin
// ValidationRules returns the rules this validator checks
ValidationRules() []string
}
ValidatorPlugin extends Plugin for validators