-
Notifications
You must be signed in to change notification settings - Fork 1
/
exceptionless.go
55 lines (46 loc) · 1.31 KB
/
exceptionless.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
package exceptionless
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
}
//ExceptionlessClient returns the configured client
var ExceptionlessClient = Exceptionless{}
func handlePolling() {
if ExceptionlessClient.ApiKey != "" && ExceptionlessClient.UpdateSettingsWhenIdleInterval > 0 {
fmt.Println("polling!")
poll()
}
}
//Configure is the function that creates an Exceptionless ExceptionlessClient
func Configure(config Exceptionless) Exceptionless {
ExceptionlessClient = config
handlePolling()
return ExceptionlessClient
}
//GetClient returns the Exceptionless client
func GetClient() Exceptionless {
return ExceptionlessClient
}
//GetConfig returns the project configuration
func GetConfig() map[string]interface{} {
return config
}
func poll() {
r := rand.New(rand.NewSource(99))
c := time.Tick(10 * time.Second)
for _ = range c {
resp := Get("projects/config", ExceptionlessClient.ApiKey)
config = resp
jitter := time.Duration(r.Int31n(ExceptionlessClient.UpdateSettingsWhenIdleInterval)) * time.Millisecond
time.Sleep(jitter)
}
}