Alternatives: HashiCorp go-plugin
RPC-based plugins for cross-platform support
Alternatives: HashiCorp go-plugin is a free Go Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Go Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why go-plugin?
The native Go plugin package is Linux/macOS only, requires identical dependency versions, and cannot unload plugins. HashiCorp go-plugin solves these problems by running plugins as separate processes communicating via RPC (gRPC or net/rpc).
Architecture
go-plugin runs the plugin binary as a subprocess. The host starts it, establishes a gRPC/net/rpc connection, and calls the plugin through a generated client. The plugin process is killed on host exit.
Defining the interface
Define the interface in a shared package, then provide a gRPC or net/rpc bridge.
// shared/interface.go
type Greeter interface {
Greet(name string) (string, error)
}Plugin side
The plugin implements the interface and registers it with go-plugin's serve mechanism:
func main() {
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: Handshake,
Plugins: map[string]plugin.Plugin{
"greeter": &GreeterPlugin{Impl: &Greeter{}},
},
GRPCServer: plugin.DefaultGRPCServer,
})
}Host side
The host launches the plugin subprocess and acquires the interface via a client:
client := plugin.NewClient(&plugin.ClientConfig{
HandshakeConfig: Handshake,
Plugins: PluginMap,
Cmd: exec.Command("./greeter-plugin"),
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
})
rpcClient, _ := client.Client()
raw, _ := rpcClient.Dispense("greeter")
greeter := raw.(Greeter)Handshake config
A shared HandshakeConfig (magic cookie key+value) prevents a non-plugin binary from accidentally being launched as a plugin:
var Handshake = plugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "GREETER_PLUGIN",
MagicCookieValue: "hello",
}Cross-platform
Because the plugin is a separate process communicating via TCP or Unix socket, it can be compiled for any platform. The host and plugin do not need identical Go versions.
Crash isolation
If a plugin crashes, the host receives an error on the next RPC call. The host can restart the plugin subprocess and reconnect without crashing itself.
Performance
go-plugin RPC adds latency compared to in-process function calls (microseconds vs nanoseconds). Acceptable for infrequent, heavyweight plugin calls; not suitable for hot loops.
Versioning
go-plugin supports protocol versioning — the host can negotiate with multiple versions of a plugin interface simultaneously, enabling gradual plugin upgrades.
Real-world usage
go-plugin powers HashiCorp Terraform providers, Vault secrets engines, and Packer builders — large ecosystems with community-developed plugins.
When to choose
Choose go-plugin over native plugins when: cross-platform support is needed, crash isolation is important, dependency versions cannot be aligned, or plugins are written by third parties.
Quick Check
How does HashiCorp go-plugin achieve crash isolation?
Recap: HashiCorp go-plugin
Key points:
- Plugins run as subprocesses; communicate via gRPC or net/rpc
- Cross-platform, crash-isolated, version-tolerant
- HandshakeConfig prevents accidental binary launching
- Performance overhead from RPC; use for heavyweight/infrequent calls
Frequently asked questions
Is the “Alternatives: HashiCorp go-plugin” lesson free?
Yes — the full text of “Alternatives: HashiCorp go-plugin” is free to read here on the web, and the Go Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Go Academy course, upgrade to CoddyKit PRO.
What will I learn in “Alternatives: HashiCorp go-plugin”?
RPC-based plugins for cross-platform support You practise Go Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Go Academy?
No prior experience is required. Go Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Alternatives: HashiCorp go-plugin” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Go Academy lesson?
Yes. Every Go Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Go plugin Package Basics
- Designing a Plugin Interface
- Dynamic Loading and Symbols
- Alternatives: HashiCorp go-plugin