-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathplugin.go
61 lines (47 loc) · 1.24 KB
/
plugin.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
60
61
package ucon
import "fmt"
type pluginContainer struct {
base interface{}
}
// HandlersScannerPlugin is an interface to make a plugin for scanning request handlers.
type HandlersScannerPlugin interface {
HandlersScannerProcess(m *ServeMux, rds []*RouteDefinition) error
}
func (p *pluginContainer) check() {
if p.HandlersScanner() != nil {
return
}
panic(fmt.Sprintf("unused plugin: %#v", p.base))
}
// HandlersScanner returns itself if it implements HandlersScannerPlugin.
func (p *pluginContainer) HandlersScanner() HandlersScannerPlugin {
if v, ok := p.base.(HandlersScannerPlugin); ok {
return v
}
return nil
}
type emptyCtx int
var background = new(emptyCtx)
func (*emptyCtx) Value(key interface{}) interface{} {
return nil
}
// Context is a key-value store.
type Context interface {
Value(key interface{}) interface{}
}
// WithValue returns a new context containing the value.
// Values contained by parent context are inherited.
func WithValue(parent Context, key interface{}, val interface{}) Context {
return &valueCtx{parent, key, val}
}
type valueCtx struct {
Context
key interface{}
val interface{}
}
func (c *valueCtx) Value(key interface{}) interface{} {
if c.key == key {
return c.val
}
return c.Context.Value(key)
}