Designing a Plugin Interface
Shared interface contracts between host and plugin
Interface-based plugins
Define a stable Go interface that plugins must implement. The host loads the plugin, retrieves the implementation, and calls it through the interface — no type assertions on every method.
type Processor interface {
Name() string
Process(ctx context.Context, data []byte) ([]byte, error)
}Plugin entry point
Each plugin exports a known symbol (e.g., Plugin) that returns the interface implementation:
// In the plugin:
var Plugin processor // exported symbol
type processor struct{}
func (p processor) Name() string { return "my-processor" }
func (p processor) Process(ctx context.Context, data []byte) ([]byte, error) {
return bytes.ToUpper(data), nil
}All lessons in this course
- Go plugin Package Basics
- Designing a Plugin Interface
- Dynamic Loading and Symbols
- Alternatives: HashiCorp go-plugin