Alternatives: HashiCorp go-plugin
RPC-based plugins for cross-platform support
Alternatives: HashiCorp go-plugin is a free Go Academy lesson on CoddyKit. This is lesson 4 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Go Academy learning path, and your progress syncs across the web and the CoddyKit app. The Go Academy course includes 4 lessons in total.
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
Learn Go with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 51
- Lessons
- 203
Frequently Asked Questions
Is the “Alternatives: HashiCorp go-plugin” lesson free?
Yes — any 3 lessons of the Go Academy learning path, including “Alternatives: HashiCorp go-plugin”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Go Academy course includes 4 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.
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