1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-24 20:48:18 +00:00

Added ListAll function on types_template.go to depaginate results on collection

This commit is contained in:
rawmind0
2020-02-10 11:26:04 +01:00
parent 99f434a2d0
commit 9035b1ea41

View File

@@ -38,6 +38,7 @@ type {{.schema.CodeName}}Client struct {
type {{.schema.CodeName}}Operations interface {
List(opts *types.ListOpts) (*{{.schema.CodeName}}Collection, error)
ListAll(opts *types.ListOpts) (*{{.schema.CodeName}}Collection, error)
Create(opts *{{.schema.CodeName}}) (*{{.schema.CodeName}}, error)
Update(existing *{{.schema.CodeName}}, updates interface{}) (*{{.schema.CodeName}}, error)
Replace(existing *{{.schema.CodeName}}) (*{{.schema.CodeName}}, error)
@@ -98,6 +99,23 @@ func (c *{{.schema.CodeName}}Client) List(opts *types.ListOpts) (*{{.schema.Code
return resp, err
}
func (c *{{.schema.CodeName}}Client) ListAll(opts *types.ListOpts) (*{{.schema.CodeName}}Collection, error) {
resp := &{{.schema.CodeName}}Collection{}
resp, err := c.List(opts)
if err != nil {
return resp, err
}
data := resp.Data
for resp, err = resp.Next(); resp != nil && err == nil; resp, err = resp.Next() {
data = append(data, resp.Data...)
}
if err != nil {
return resp, err
}
resp.Data = data
return resp, err
}
func (cc *{{.schema.CodeName}}Collection) Next() (*{{.schema.CodeName}}Collection, error) {
if cc != nil && cc.Pagination != nil && cc.Pagination.Next != "" {
resp := &{{.schema.CodeName}}Collection{}