Documentation
¶
Overview ¶
Package extensibility dynamically loads external Go plugins using `LoadPlugin`. Just provide a symbol name (e.g., a function) to integrate new features on-the-fly—no rebuilds or redeploys required.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadPlugin ¶
LoadPlugin loads a plugin from the given path and returns the symbol with the given name.
Example ¶
This example has no Output comment: it needs a plugin built beside it.
package main
import (
"fmt"
"log"
"github.com/andygeiss/cloud-native-utils/extensibility"
)
func main() {
// The plugin is built separately, by the same toolchain as this program:
//
// go build -buildmode=plugin -o adapter.so adapter.go
//
// The consumer declares the interface it wants back, so the plugin never
// has to import this package.
type Repository interface {
FindByID(id string) (name string, err error)
}
adapter, err := extensibility.LoadPlugin[Repository]("adapter.so", "Adapter")
if err != nil {
log.Fatal(err)
}
name, err := adapter.FindByID("1")
if err != nil {
log.Fatal(err)
}
fmt.Println(name)
}
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.