0PricingLogin
Go Academy · Lesson

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

  1. Go plugin Package Basics
  2. Designing a Plugin Interface
  3. Dynamic Loading and Symbols
  4. Alternatives: HashiCorp go-plugin
← Back to Go Academy