Improve plugins builder.

This commit is contained in:
Ludovic Fernandez 2020-09-07 13:58:03 +02:00 committed by GitHub
parent 1dbee90d34
commit 66d151df77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 10 deletions

View file

@ -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.