-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.go
45 lines (38 loc) · 982 Bytes
/
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
// The purpose of this example is to show how to query a dataset using a legacy
// query.
package main
import (
"context"
"fmt"
"log"
"os"
"time"
"github.com/axiomhq/axiom-go/axiom"
"github.com/axiomhq/axiom-go/axiom/querylegacy"
)
func main() {
// Export "AXIOM_DATASET" in addition to the required environment variables.
dataset := os.Getenv("AXIOM_DATASET")
if dataset == "" {
log.Fatal("AXIOM_DATASET is required")
}
// 1. Initialize the Axiom API client.
client, err := axiom.NewClient()
if err != nil {
log.Fatal(err)
}
// 2. Query all events in the last minute ⚡
res, err := client.QueryLegacy(context.Background(), dataset, querylegacy.Query{
StartTime: time.Now().Add(-time.Minute),
EndTime: time.Now(),
}, querylegacy.Options{})
if err != nil {
log.Fatal(err)
} else if len(res.Matches) == 0 {
log.Fatal("No matches found")
}
// 3. Print the queried results.
for _, match := range res.Matches {
fmt.Println(match.Data)
}
}