plugin

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package plugin provides a flexible plugin system for extending Buffalo functionality.

Index

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 NewLoader

func NewLoader(log *logger.Logger, pluginDirs ...string) *Loader

NewLoader creates a new plugin loader

func (*Loader) GetLoadedPlugins

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

GetLoadedPlugins returns names of all loaded plugins

func (*Loader) LoadAll

func (l *Loader) LoadAll(registry *Registry) error

LoadAll discovers and loads all plugins from configured directories

func (*Loader) LoadByName

func (l *Loader) LoadByName(name string, registry *Registry) error

LoadByName loads a specific plugin by name from configured directories

func (*Loader) Unload

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

Unload unloads a plugin (note: Go plugins cannot truly be unloaded)

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

func NewRegistry(log *logger.Logger) *Registry

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

func (r *Registry) ExecuteHook(ctx context.Context, hookPoint HookPoint, input *Input) error

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) InitAll

func (r *Registry) InitAll() error

InitAll initializes all enabled plugins

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) Register

func (r *Registry) Register(plugin Plugin, config Config) error

Register registers a plugin with the registry

func (*Registry) ShutdownAll

func (r *Registry) ShutdownAll() error

ShutdownAll shuts down all plugins

func (*Registry) Unregister

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

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) Execute

func (v *SimpleNamingValidator) Execute(ctx context.Context, input *Input) (*Output, error)

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 (*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

Directories

Path Synopsis
Package examples provides example plugins for Buffalo This demonstrates how to create a simple validator plugin
Package examples provides example plugins for Buffalo This demonstrates how to create a simple validator plugin

Jump to

Keyboard shortcuts

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