/
plugin.go
43 lines (35 loc) · 809 Bytes
/
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
package challenger
import (
"log"
)
type plugin struct {
name string
init func(logger *log.Logger) error
opts interface{}
gethandler func() Handler
}
func (p *plugin) GetName() string {
return p.name
}
func (p *plugin) GetOpts() interface{} {
return p.opts
}
func (p *plugin) GetHandler() Handler {
return p.gethandler()
}
func (p *plugin) Init(logger *log.Logger) error {
logger.Printf("challenger: %v init", p.name)
if p.init != nil {
return p.init(logger)
}
return nil
}
// NewFromHandler creates a Challenger with given functions
func NewFromHandler(name string, gethandler func() Handler, opts interface{}, init func(glogger *log.Logger) error) Provider {
return &plugin{
name: name,
init: init,
opts: opts,
gethandler: gethandler,
}
}