-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
74 lines (63 loc) · 1.66 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package apidGatewayTrace
import (
"github.com/apid/apid-core"
"net/http"
"sync"
)
var (
log apid.LogService // set in initPlugin
services apid.Services
config apid.ConfigService
)
const (
signalEndpoint = "/tracesignals"
uploadEndpoint = "/uploadtrace"
)
//initServices initializes global apid-core based variables
func initServices(s apid.Services) {
services = s
log = services.Log().ForModule("apidGatewayTrace")
config = services.Config()
}
//initPlugin creates the necessary structures for interacting with the database and blobstore, as well as the API impl
func initPlugin(s apid.Services) (apid.PluginData, error) {
initServices(s)
log.Debugf("Initializing %s", pluginData.Name)
dbMan := &dbManager{
data: services.Data(),
dbMux: sync.RWMutex{},
}
apiMan := &apiManager{
dbMan: dbMan,
bsClient: &blobstoreClient{
httpClient: &http.Client{
Transport: &http.Transport{
MaxIdleConnsPerHost: maxIdleConnsPerHost,
},
Timeout: httpTimeout,
CheckRedirect: func(req *http.Request, _ []*http.Request) error {
req.Header.Set("Authorization", getBearerToken())
return nil
},
},
},
signalEndpoint: signalEndpoint,
uploadEndpoint: uploadEndpoint,
apiInitialized: false,
newSignal: make(chan interface{}),
addSubscriber: make(chan chan interface{}),
}
// initialize event handler
eventHandler := &apigeeSyncHandler{
dbMan: dbMan,
apiMan: apiMan,
closed: false,
}
eventHandler.initListener(services)
log.Debug("end init")
return pluginData, nil
}
//init is the entrypoint into the plugin, which registers this plugin with apid core
func init() {
apid.RegisterPlugin(initPlugin, pluginData)
}