File tree Expand file tree Collapse file tree 1 file changed +31
-16
lines changed Expand file tree Collapse file tree 1 file changed +31
-16
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ package cfclient
22
33import (
44 "fmt"
5- "log"
65 "strings"
76)
87
@@ -222,25 +221,41 @@ func (client *Client) DeleteUserAsAccountAdmin(accountId, userId string) error {
222221
223222func (client * Client ) GetAllUsers () (* []User , error ) {
224223
225- opts := RequestOptions {
226- Path : "/admin/user" ,
227- Method : "GET" ,
228- }
224+ limitPerQuery := 100
225+ bIsDone := false
226+ nPageIndex := 1
229227
230- resp , err := client .RequestAPI (& opts )
231- if err != nil {
232- return nil , err
233- }
228+ var allUsers []User
234229
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+ }
241256 }
242257
243- return & users , nil
258+ return & allUsers , nil
244259}
245260
246261func (client * Client ) GetUserByID (userId string ) (* User , error ) {
You can’t perform that action at this time.
0 commit comments