{"modulePath":"github.com/micro-community/micro","version":"v0.20.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package plugin\n\n## Functions\n\n```go\nfunc Register(plugin Plugin) error\n```\nRegister registers a global plugins\n\n## Types\n\n```go\ntype Handler func(http.Handler) http.Handler\n```\nHandler is the plugin middleware handler which wraps an existing http.Handler passed in. Its the responsibility of the Handler to call the next http.Handler in the chain.\n\n```go\ntype Manager interface {\n\tPlugins() []Plugin\n\tRegister(Plugin) error\n}\n```\nManager is the plugin manager which stores plugins and allows them to be retrieved. This is used by all the components of micro.\n\n```go\nfunc NewManager() Manager\n```\nNewManager creates a new plugin manager\n\n```go\ntype Option func(o *Options)\n```\n\n```go\nfunc WithCommand(cmd ...cli.Command) Option\n```\nWithCommand adds commands to a plugin\n\n```go\nfunc WithFlag(flag ...cli.Flag) Option\n```\nWithFlag adds flags to a plugin\n\n```go\nfunc WithHandler(h ...Handler) Option\n```\nWithHandler adds middleware handlers to\n\n```go\nfunc WithInit(fn func(*cli.Context) error) Option\n```\nWithInit sets the init function\n\n```go\nfunc WithName(n string) Option\n```\nWithName defines the name of the plugin\n\n```go\ntype Options struct {\n\tName     string\n\tFlags    []cli.Flag\n\tCommands []cli.Command\n\tHandlers []Handler\n\tInit     func(*cli.Context) error\n}\n```\nOptions are used as part of a new plugin\n\n```go\ntype Plugin interface {\n\t// Global Flags\n\tFlags() []cli.Flag\n\t// Sub-commands\n\tCommands() []cli.Command\n\t// Handle is the middleware handler for HTTP requests. We pass in\n\t// the existing handler so it can be wrapped to create a call chain.\n\tHandler() Handler\n\t// Init called when command line args are parsed.\n\t// The initialised cli.Context is passed in.\n\tInit(*cli.Context) error\n\t// Name of the plugin\n\tString() string\n}\n```\nPlugin is the interface for plugins to micro. It differs from go-micro in that it's for the micro API, Web, Sidecar, CLI. It's a method of building middleware for the HTTP side.\n\n```go\nfunc NewPlugin(opts ...Option) Plugin\n```\nNewPlugin makes it easy to create a new plugin\n\n```go\nfunc Plugins() []Plugin\n```\nPlugins lists the global plugins\n\n","path":"github.com/micro-community/micro/plugin","name":"plugin","synopsis":"","isRedistributable":true}
