listAll[T] working

This commit is contained in:
Ian Gulliver
2024-06-22 15:35:58 -07:00
parent ea516a559f
commit b615906097

View File

@@ -125,18 +125,11 @@ func listAll[T any](ctx context.Context, c *Client, db, table string, params url
for { for {
resp := map[string]any{} resp := map[string]any{}
err := c.get(ctx, db, table, "", params, resp) err := c.get(ctx, db, table, "", params, &resp)
if err != nil { if err != nil {
return nil, err return nil, err
} }
off, found := resp["offset"]
if !found {
return ret, nil
}
params.Set("offset", off.(string))
subresp, err := json.Marshal(resp[key]) subresp, err := json.Marshal(resp[key])
if err != nil { if err != nil {
return nil, err return nil, err
@@ -144,11 +137,19 @@ func listAll[T any](ctx context.Context, c *Client, db, table string, params url
obj := []*T{} obj := []*T{}
err = json.Unmarshal(subresp, obj) err = json.Unmarshal(subresp, &obj)
if err != nil { if err != nil {
return nil, err return nil, err
} }
ret = append(ret, obj...) ret = append(ret, obj...)
off, found := resp["offset"]
if !found {
return ret, nil
}
params.Set("offset", off.(string))
} }
} }