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