-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.go
70 lines (59 loc) · 1.54 KB
/
common.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
package common
import (
"fmt"
"strings"
"github.com/zscaler/zscaler-sdk-go/zia"
)
const pageSize = 1000
type IDNameExtensions struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}
type IDExtensions struct {
ID int `json:"id,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}
type UserGroups struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
IdpID int `json:"idp_id,omitempty"`
Comments string `json:"comments,omitempty"`
}
type UserDepartment struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
IdpID int `json:"idp_id,omitempty"`
Comments string `json:"comments,omitempty"`
Deleted bool `json:"deleted,omitempty"`
}
type DeviceGroups struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}
type Devices struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}
func ReadAllPages[T any](client *zia.Client, endpoint string, list *[]T) error {
if list == nil {
return nil
}
page := 1
if !strings.Contains(endpoint, "?") {
endpoint += "?"
}
for {
pageItems := []T{}
err := client.Read(fmt.Sprintf("%s&pageSize=%d&page=%d", endpoint, pageSize, page), &pageItems)
if err != nil {
return err
}
*list = append(*list, pageItems...)
if len(pageItems) < pageSize {
break
}
page++
}
return nil
}