-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
50 lines (40 loc) · 901 Bytes
/
config.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
package main
import (
"encoding/json"
"sync"
"github.com/Kong/go-pdk"
)
type Config struct {
Datasources []configDatasource `json:"datasources" yaml:"datasources"`
Injector configInjector `json:"injector" yaml:"injector"`
omniplug *Omniplug
once sync.Once
onceErr error
}
func (conf *Config) Init() (err error) {
conf.once.Do(func() {
v, err := json.Marshal(conf)
if err != nil {
conf.onceErr = err
return
}
conf.omniplug = &Omniplug{}
if conf.onceErr = json.Unmarshal(v, conf.omniplug); conf.onceErr != nil {
return
}
if conf.onceErr = conf.omniplug.Init(); conf.onceErr != nil {
return
}
})
return conf.onceErr
}
func (conf *Config) Access(kong *pdk.PDK) {
if err := conf.Init(); err != nil {
kong.Log.Err(err.Error())
kong.Response.ExitStatus(500)
}
conf.omniplug.Access(kong)
}
func NewConfig() interface{} {
return &Config{}
}