-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
plugins.go
59 lines (46 loc) · 1.47 KB
/
plugins.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package middleware
import (
"context"
"errors"
"net/http"
"github.com/opentracing/opentracing-go/ext"
"github.com/traefik/traefik/v2/pkg/config/dynamic"
"github.com/traefik/traefik/v2/pkg/plugins"
"github.com/traefik/traefik/v2/pkg/tracing"
)
// PluginsBuilder the plugin's builder interface.
type PluginsBuilder interface {
Build(pName string, config map[string]interface{}, middlewareName string) (plugins.Constructor, error)
}
func findPluginConfig(rawConfig map[string]dynamic.PluginConf) (string, map[string]interface{}, error) {
if len(rawConfig) != 1 {
return "", nil, errors.New("invalid configuration: no configuration or too many plugin definition")
}
var pluginType string
var rawPluginConfig map[string]interface{}
for pType, pConfig := range rawConfig {
pluginType = pType
rawPluginConfig = pConfig
}
if pluginType == "" {
return "", nil, errors.New("missing plugin type")
}
return pluginType, rawPluginConfig, nil
}
type traceablePlugin struct {
name string
h http.Handler
}
func newTraceablePlugin(ctx context.Context, name string, plug plugins.Constructor, next http.Handler) (*traceablePlugin, error) {
h, err := plug(ctx, next)
if err != nil {
return nil, err
}
return &traceablePlugin{name: name, h: h}, nil
}
func (s *traceablePlugin) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
s.h.ServeHTTP(rw, req)
}
func (s *traceablePlugin) GetTracingInformation() (string, ext.SpanKindEnum) {
return s.name, tracing.SpanKindNoneEnum
}