我没有一个包可以做到这一点,但对如何做到这一点有一些想法 - 希望它会有所帮助。
有Registry和Plugin接口,可能是这样的:
type Registry {
// Register registers a plugin under name
Register(name string, plugin *Plugin) error
// Get plugin by name
Get(name string) (*Plugin, error)
}
// Global Registry
var GlobalRegistry Registry
type Plugin interface {
// Init is called upon plugin initialization. Will be in dependency order
Init(reg Registry) error
// Execute plugin command
Exec(name string, args... interface{}) (interface{}, error)
}
Run Code Online (Sandbox Code Playgroud)go build -tags plugin1,plugin2