-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgologz.go
80 lines (68 loc) · 1.83 KB
/
gologz.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
75
76
77
78
79
80
package gologz
import (
"encoding/json"
"strings"
)
const (
euURL = "https://api-eu.logz.io/v1" // European Accounts URL
usURL = "https://api.logz.io/v1" // United States Accounts URL
)
// Logzio client structure with needed data to authenticate and which url to access
type Logzio struct {
Token string
BaseURL string
fetcher func(parameters *request, logzioURL, token string) ([]byte, error)
}
// New returns a new client using a application token and the service region
func New(token, region string) *Logzio {
client := Logzio{
Token: token,
BaseURL: euURL,
fetcher: fetch,
}
if strings.ToLower(region) == "us" {
client.BaseURL = usURL
}
return &client
}
// Trace a log based on a string input with a start point and a limit
func (logz *Logzio) Trace(input string, start, limit int) (*LogzResponse, error) {
traces, err := logz.fetcher(&request{
Endpoint: "/search",
Query: queryObject{
From: start,
Size: limit,
QueryType: &queryType{
String: &queryString{
input,
},
},
},
}, logz.BaseURL, logz.Token)
if err != nil {
return nil, err
}
traceTransactionResponse := new(LogzResponse)
return traceTransactionResponse, json.Unmarshal(traces, &traceTransactionResponse)
}
// TracePairs traces a log with key values input with a start point and a limit
func (logz *Logzio) TracePairs(input map[string]interface{}, start, limit int) (*LogzResponse, error) {
arrangedPairs := composePairs(input)
traces, err := logz.fetcher(&request{
Endpoint: "/search",
Query: queryObject{
From: start,
Size: limit,
QueryType: &queryType{
String: &queryString{
arrangedPairs,
},
},
},
}, logz.BaseURL, logz.Token)
if err != nil {
return nil, err
}
traceTransactionResponse := new(LogzResponse)
return traceTransactionResponse, json.Unmarshal(traces, &traceTransactionResponse)
}