-
Notifications
You must be signed in to change notification settings - Fork 1
/
getVisits.go
63 lines (51 loc) · 1.48 KB
/
getVisits.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
package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/fingerprintjs/fingerprint-pro-server-api-go-sdk/v7/sdk"
"log"
"os"
"github.com/joho/godotenv"
)
func main() {
cfg := sdk.NewConfiguration()
client := sdk.NewAPIClient(cfg)
// Load environment variables
godotenv.Load()
// Default region is sdk.RegionUS
if os.Getenv("REGION") == "eu" {
cfg.ChangeRegion(sdk.RegionEU)
}
if os.Getenv("REGION") == "ap" {
cfg.ChangeRegion(sdk.RegionAsia)
}
// Configure authorization, in our case with API Key
auth := context.WithValue(context.Background(), sdk.ContextAPIKey, sdk.APIKey{
Key: os.Getenv("FINGERPRINT_API_KEY"),
})
// Usually this data will come from your frontend app
visitorId := os.Getenv("VISITOR_ID")
opts := sdk.FingerprintApiGetVisitsOpts{
RequestId: os.Getenv("REQUEST_ID"),
}
response, httpRes, err := client.FingerprintApi.GetVisits(auth, visitorId, &opts)
fmt.Printf("%+v\n", httpRes)
if err != nil {
var tooManyRequestsError *sdk.TooManyRequestsError
if errors.As(err, &tooManyRequestsError) {
log.Printf("Too many requests, retry after %d seconds", tooManyRequestsError.RetryAfter())
} else {
log.Fatalf("Error: %s, %s", err.Code(), err.Error())
}
}
fmt.Printf("Got response with visitorId: %s", response.VisitorId)
// Print full response as JSON
responseJsonData, jsonErr := json.MarshalIndent(response, "", " ")
if jsonErr != nil {
fmt.Println("Error:", jsonErr)
return
}
fmt.Println(string(responseJsonData))
}