This repository was archived by the owner on Aug 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.go
60 lines (47 loc) · 1.45 KB
/
init.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
package apidCounters
import (
"fmt"
"github.com/30x/apid-core"
)
const (
configCountersBasePath = "counters_base_path"
countersBasePathDefault = "/counters"
)
// keep track of the services that this plugin will use
// note: services would also be available directly via the package global "apid" (eg. `apid.Log()`)
var (
log apid.LogService
config apid.ConfigService
)
// apid.RegisterPlugin() is required to be called in init()
func init() {
apid.RegisterPlugin(initPlugin, pluginData)
}
// initPlugin will be called by apid to initialize
func initPlugin(services apid.Services) (apid.PluginData, error) {
// set a logger that is annotated for this plugin
log = services.Log().ForModule("counters")
log.Debug("start init")
// set configuration
config = services.Config()
// set plugin config defaults
config.SetDefault(configCountersBasePath, countersBasePathDefault)
// check for any missing required configuration values
// in this example we check for someConfigurationKey, but normally we wouldn't check defaulted values
for _, key := range []string{configCountersBasePath} {
if !config.IsSet(key) {
return pluginData, fmt.Errorf("Missing required config value: %s", key)
}
}
// register APIs (see api.go)
initAPI(services)
// register for events (see events.go)
initEvents(services)
// set data service (see data.go)
err := initDB(services)
if err != nil {
return pluginData, err
}
log.Debug("end init")
return pluginData, nil
}