-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
67 lines (56 loc) · 1.38 KB
/
main.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
package main
import (
"fmt"
"math/rand"
"time"
)
var config map[string]interface{} = nil
//Exceptionless type defines the client configuration structure
type Exceptionless struct {
apiKey string
serverURL string
updateSettingsWhenIdleInterval int32
includePrivateInformation bool
}
var client = Exceptionless{}
func main() {
handlePolling()
}
func handlePolling() {
if client.apiKey != "" && client.updateSettingsWhenIdleInterval > 0 {
fmt.Println("polling!")
poll()
}
}
//Configure is the function that creates an Exceptionless client
func Configure(config Exceptionless) Exceptionless {
client = config
handlePolling()
return client
}
//GetClient returns the Exceptionless client
func GetClient() Exceptionless {
return client
}
//GetConfig returns the project configuration
func GetConfig() map[string]interface{} {
return config
}
//SubmitEvent sends log events to Exceptionless
func SubmitEvent(eventBody string) string {
if client.apiKey == "" {
fmt.Println("is zero value")
}
resp := Post("events", eventBody, client.apiKey)
return resp
}
func poll() {
r := rand.New(rand.NewSource(99))
c := time.Tick(10 * time.Second)
for _ = range c {
resp := Get("projects/config", client.apiKey)
config = resp
jitter := time.Duration(r.Int31n(client.updateSettingsWhenIdleInterval)) * time.Millisecond
time.Sleep(jitter)
}
}