Plugin Architectures in Go

Patterns and Trade-Offs

Go plugins are dynamically loadable shared libraries built with -buildmode=plugin that extend host programs at runtime.

Go plugins are shared libraries built with -buildmode=plugin that load at runtime via plugin.Open, allowing dynamic code extension without recompilation. They require CGO, matching module paths, and identical dependency versions to the host program to avoid runtime errors.

go build -buildmode=plugin -o myplugin.so myplugin.go
go run main.go

In main.go:

import "plugin"
p, _ := plugin.Open("myplugin.so")
fn, _ := p.Lookup("MyFunction")
fn.(func())()