Improve plugins builder.
This commit is contained in:
parent
1dbee90d34
commit
66d151df77
4 changed files with 22 additions and 10 deletions
|
@ -15,6 +15,9 @@ import (
|
|||
|
||||
const devPluginName = "dev"
|
||||
|
||||
// Constructor creates a plugin handler.
|
||||
type Constructor func(context.Context, http.Handler) (http.Handler, error)
|
||||
|
||||
// pluginContext The static part of a plugin configuration.
|
||||
type pluginContext struct {
|
||||
// GoPath plugin's GOPATH
|
||||
|
@ -89,7 +92,7 @@ func NewBuilder(client *Client, plugins map[string]Descriptor, devPlugin *DevPlu
|
|||
}
|
||||
|
||||
// Build builds a plugin.
|
||||
func (b Builder) Build(pName string, config map[string]interface{}, middlewareName string) (*Middleware, error) {
|
||||
func (b Builder) Build(pName string, config map[string]interface{}, middlewareName string) (Constructor, error) {
|
||||
if b.descriptors == nil {
|
||||
return nil, fmt.Errorf("plugin: no plugin definition in the static configuration: %s", pName)
|
||||
}
|
||||
|
@ -99,7 +102,12 @@ func (b Builder) Build(pName string, config map[string]interface{}, middlewareNa
|
|||
return nil, fmt.Errorf("plugin: unknown plugin type: %s", pName)
|
||||
}
|
||||
|
||||
return newMiddleware(descriptor, config, middlewareName)
|
||||
m, err := newMiddleware(descriptor, config, middlewareName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return m.NewHandler, err
|
||||
}
|
||||
|
||||
// Middleware is a HTTP handler plugin wrapper.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue