Lab 13: Plugin Architecture

Time: 60 minutes | Level: Architect | Docker: golang:1.22-alpine

Overview

Plugin systems in Go: plugin package (Open/Lookup), hashicorp/go-plugin (gRPC-based), interface-contract versioning, hot-reload pattern, WASM-based plugins for isolation, and capability-based plugin security.


Step 1: Go plugin Package

// plugin/greeter/main.go — compiled as shared library
package main

// Exported symbol: must be package-level variable or function
var PluginName = "greeter-v1"

func Greet(name string) string {
    return "Hello, " + name + "! (from plugin)"
}

// Build:
// go build -buildmode=plugin -o greeter.so ./plugin/greeter/

// Limitations:
// - Same Go version (exact match required)
// - Linux/macOS only (no Windows)
// - Cannot unload (process-lifetime)
// - Plugin and host must use same module path for shared types

Step 2: Plugin Interface Contract


Step 3: hashicorp/go-plugin — Production Plugins


Step 4: Hot Reload Plugin Pattern


Step 5: WASM-Based Plugins


Step 6: Capability-Based Security


Step 7: Plugin Registry


Step 8: Capstone — Plugin Build and Load

📸 Verified Output:


Summary

Approach
Isolation
Cross-Platform
Reload

plugin package

None (same process)

Linux/macOS

No

hashicorp/go-plugin

Full (subprocess)

All platforms

Kill + restart

WASM (wazero)

Sandboxed

All platforms

Yes

Interface registry

None

All

Yes (rebuild)

Capability-based

API surface

All

With any approach

Last updated