Skip to content

hansmi/staticplug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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))
  }
}

About

Build-time plugins for programs written in Go.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages