-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtreblle.go
55 lines (44 loc) · 1.06 KB
/
treblle.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 treblle
import (
"bytes"
"encoding/json"
"math/rand"
"net/http"
"time"
)
const (
timeoutDuration = 2 * time.Second
)
type BaseUrlOptions struct {
Debug bool
}
func getTreblleBaseUrl() string {
if Config.Debug {
return "https://debug.treblle.com/"
}
treblleBaseUrls := []string{
"https://rocknrolla.treblle.com",
"https://punisher.treblle.com",
"https://sicario.treblle.com",
}
rand.Seed(time.Now().Unix())
randomUrlIndex := rand.Intn(len(treblleBaseUrls))
return treblleBaseUrls[randomUrlIndex]
}
func sendToTreblle(treblleInfo MetaData) {
baseUrl := getTreblleBaseUrl()
bytesRepresentation, err := json.Marshal(treblleInfo)
if err != nil {
return
}
req, err := http.NewRequest(http.MethodPost, baseUrl, bytes.NewBuffer(bytesRepresentation))
if err != nil {
return
}
// Set the content type from the writer, it includes necessary boundary as well
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-api-key", Config.APIKey)
// Do the request
client := &http.Client{Timeout: timeoutDuration}
_, _ = client.Do(req)
}