plugin

Guided tour · Misc · pkg.go.dev →

Load Go shared objects (.so) at runtime. Linux/macOS only. Fragile — all plugins must match the host's exact toolchain and deps. Rarely the right tool.

Usage

Build a plugin

go build -buildmode=plugin -o hello.so hello.go

Open and look up symbols

p, err := plugin.Open("hello.so")
if err != nil { log.Fatal(err) }

sym, err := p.Lookup("Greet")
if err != nil { log.Fatal(err) }

greet := sym.(func(string) string)
fmt.Println(greet("world"))