github.com/annwntech/go-micro/v2@v2.9.5/plugin/plugin.go (about) 1 // Package plugin provides the ability to load plugins 2 package plugin 3 4 // Plugin is a plugin loaded from a file 5 type Plugin interface { 6 // Initialise a plugin with the config 7 Init(c *Config) error 8 // Load loads a .so plugin at the given path 9 Load(path string) (*Config, error) 10 // Build a .so plugin with config at the path specified 11 Build(path string, c *Config) error 12 } 13 14 // Config is the plugin config 15 type Config struct { 16 // Name of the plugin e.g rabbitmq 17 Name string 18 // Type of the plugin e.g broker 19 Type string 20 // Path specifies the import path 21 Path string 22 // NewFunc creates an instance of the plugin 23 NewFunc interface{} 24 } 25 26 var ( 27 // Default plugin loader 28 DefaultPlugin = NewPlugin() 29 ) 30 31 // NewPlugin creates a new plugin interface 32 func NewPlugin() Plugin { 33 return &plugin{} 34 } 35 36 func Build(path string, c *Config) error { 37 return DefaultPlugin.Build(path, c) 38 } 39 40 func Load(path string) (*Config, error) { 41 return DefaultPlugin.Load(path) 42 } 43 44 func Init(c *Config) error { 45 return DefaultPlugin.Init(c) 46 }