File tree 1 file changed +32
-16
lines changed
1 file changed +32
-16
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ package cfclient
2
2
3
3
import (
4
4
"fmt"
5
- "log"
5
+ // "log"
6
6
"strings"
7
7
)
8
8
@@ -222,25 +222,41 @@ func (client *Client) DeleteUserAsAccountAdmin(accountId, userId string) error {
222
222
223
223
func (client * Client ) GetAllUsers () (* []User , error ) {
224
224
225
- opts := RequestOptions {
226
- Path : "/admin/user" ,
227
- Method : "GET" ,
228
- }
225
+ limitPerQuery := 100
226
+ bIsDone := false
227
+ nPageIndex := 1
229
228
230
- resp , err := client .RequestAPI (& opts )
231
- if err != nil {
232
- return nil , err
233
- }
229
+ var allUsers []User
234
230
235
- var users []User
236
- respStr := string (resp )
237
- log .Printf ("[INFO] GetAllUsers resp: %s" , respStr )
238
- err = DecodeResponseInto (resp , & users )
239
- if err != nil {
240
- return nil , err
231
+ for ! bIsDone {
232
+ var userPaginatedResp struct {Docs []User `json:"docs"` }
233
+
234
+ opts := RequestOptions {
235
+ Path : fmt .Sprintf ("/admin/user?limit=%d&page=%d" , limitPerQuery , nPageIndex ),
236
+ Method : "GET" ,
237
+ }
238
+
239
+ resp , err := client .RequestAPI (& opts )
240
+
241
+ if err != nil {
242
+ return nil , err
243
+ }
244
+
245
+ err = DecodeResponseInto (resp , & userPaginatedResp )
246
+
247
+ if err != nil {
248
+ return nil , err
249
+ }
250
+
251
+ if len (userPaginatedResp .Docs ) > 0 {
252
+ allUsers = append (allUsers ,userPaginatedResp .Docs ... )
253
+ nPageIndex ++
254
+ } else {
255
+ bIsDone = true
256
+ }
241
257
}
242
258
243
- return & users , nil
259
+ return & allUsers , nil
244
260
}
245
261
246
262
func (client * Client ) GetUserByID (userId string ) (* User , error ) {
You can’t perform that action at this time.
0 commit comments