Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 1.24 KB

README.md

File metadata and controls

41 lines (31 loc) · 1.24 KB

Static plugins for Go binaries

Latest release CI workflow Go reference

The staticplug Go module implements compile-time plugins. Each plugin is a type that gets compiled into the executable. Once the executable is built its plugins and their functionality is fixed.

Modules wanting to make use of plugins need to create a registry:

var Registry = staticplug.NewRegistry()

Plugins register with the registry as part of the process initialization:

func init() {
  pkg.Registry.MustRegister(&myPlugin{})
}

The extendable module discovers plugins using implemented interfaces:

func Do() {
  plugins, err := Registry.PluginsImplementing((*Calculator)(nil))
  …
  for _, info := range plugins {
    p, err := info.New()
    …
    log.Printf("sum = %d", p.(Calculator).Add(1, 2))
  }
}