mirror of
https://github.com/rancher/norman.git
synced 2025-09-25 06:26:50 +00:00
Added ListAll function on types_template.go to depaginate results on collection
This commit is contained in:
@@ -38,6 +38,7 @@ type {{.schema.CodeName}}Client struct {
|
|||||||
|
|
||||||
type {{.schema.CodeName}}Operations interface {
|
type {{.schema.CodeName}}Operations interface {
|
||||||
List(opts *types.ListOpts) (*{{.schema.CodeName}}Collection, error)
|
List(opts *types.ListOpts) (*{{.schema.CodeName}}Collection, error)
|
||||||
|
ListAll(opts *types.ListOpts) (*{{.schema.CodeName}}Collection, error)
|
||||||
Create(opts *{{.schema.CodeName}}) (*{{.schema.CodeName}}, error)
|
Create(opts *{{.schema.CodeName}}) (*{{.schema.CodeName}}, error)
|
||||||
Update(existing *{{.schema.CodeName}}, updates interface{}) (*{{.schema.CodeName}}, error)
|
Update(existing *{{.schema.CodeName}}, updates interface{}) (*{{.schema.CodeName}}, error)
|
||||||
Replace(existing *{{.schema.CodeName}}) (*{{.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
|
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) {
|
func (cc *{{.schema.CodeName}}Collection) Next() (*{{.schema.CodeName}}Collection, error) {
|
||||||
if cc != nil && cc.Pagination != nil && cc.Pagination.Next != "" {
|
if cc != nil && cc.Pagination != nil && cc.Pagination.Next != "" {
|
||||||
resp := &{{.schema.CodeName}}Collection{}
|
resp := &{{.schema.CodeName}}Collection{}
|
||||||
|
Reference in New Issue
Block a user