Skip to content

Commit 9ab6b32

Browse files
committed
review feedback
1 parent 6da4058 commit 9ab6b32

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

examples/auditlog/auditlog.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
func main() {
16-
// Specify the project ID, startTime and endTIme
16+
// Specify the project ID, startTime and endTime
1717
projectId := "PROJECT_ID"
1818
startTime := time.Now().Add(-time.Hour * 24)
1919
endTime := time.Now()
@@ -33,13 +33,20 @@ func main() {
3333
Limit(limit)
3434
result, err := listProjectLogsReq.Execute()
3535

36+
// To fetch all audit log items within a specified time range, we must implement pagination, because the api returns only
37+
// up to 100 elements per request. We store the result of each request in `allItems`. The response includes a cursor,
38+
// if more elements are available. This cursor must be used to get the next set of elements.
39+
// The api has a rate limit, which can be reached when all elements will be fetched with pagination or if you do multiple request.
40+
// The rate limit should be taken care in this case.
3641
var allItems []auditlog.AuditLogEntryResponse
3742
for {
3843
if err != nil {
3944
var oapiErr *oapierror.GenericOpenAPIError
4045
if errors.As(err, &oapiErr) {
41-
// reached rate limit
46+
// Check if rate limit is reached
4247
if oapiErr.StatusCode == http.StatusTooManyRequests {
48+
// In case you want to fetch all items, you may want to wait some time and retry the request.
49+
// In this example we just stop here the pagination.
4350
fmt.Fprintf(os.Stderr, "[Auditlog API] Too Many Requests: %v\n", string(oapiErr.Body))
4451
break
4552
}
@@ -57,7 +64,7 @@ func main() {
5764

5865
// If cursor is not set, end of logs is reached
5966
if result.Cursor == nil {
60-
fmt.Printf("[Auditlog API] Successfully all items.\n")
67+
fmt.Printf("[Auditlog API] Successfully fetched all items.\n")
6168
break
6269
}
6370

0 commit comments

Comments
 (0)