snippet/exceptionless/exceptionless.go

68 lines
1.4 KiB
Go

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
}
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)
}
}