github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/swr/v2/repositories/List.go (about) 1 package repositories 2 3 import ( 4 "fmt" 5 6 "github.com/opentelekomcloud/gophertelekomcloud" 7 "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" 8 "github.com/opentelekomcloud/gophertelekomcloud/pagination" 9 ) 10 11 type ListOpts struct { 12 // The value can only be self, indicating that the image is a self-owned image. 13 Center string `q:"center"` 14 // Organization (namespace) name 15 Organization string `q:"namespace"` 16 // Image repository name 17 Name string `q:"name"` 18 // Image repository type. The value can be app_server, linux, framework_app, database, lang, other, windows, or arm. 19 Category string `q:"category"` 20 // Sorting criteria. The value can be name, updated_time, or tag_count. 21 // Ensure that the order_column and order_type parameters are used together 22 OrderColumn string `q:"order_column"` 23 // Sorting type. You can set this parameter to desc (descending sort) and asc (ascending sort). 24 // Ensure that the order_column and order_type parameters are used together. 25 OrderType string `q:"order_type"` 26 // Start index. 27 // Ensure that the offset and limit parameters are used together. 28 Offset *int `q:"offset,omitempty"` 29 // Number of returned records. 30 // Ensure that the offset and limit parameters are used together. 31 Limit int `q:"limit,omitempty"` 32 } 33 34 func (opts ListOpts) ToRepositoryListQuery() (string, error) { 35 if opts.Limit == 0 && opts.Offset != nil { 36 opts.Limit = 25 37 } 38 39 if opts.Limit != 0 && opts.Offset == nil { 40 return "", fmt.Errorf("offset has to be defined if the limit is set") 41 } 42 43 if (opts.OrderColumn != "" && opts.OrderType == "") || (opts.OrderColumn == "" && opts.OrderType != "") { 44 return "", fmt.Errorf("`OrderColumn` and `OrderType` should always be used together") 45 } 46 47 q, err := golangsdk.BuildQueryString(opts) 48 if err != nil { 49 return "", err 50 } 51 52 return q.String(), nil 53 } 54 55 func List(client *golangsdk.ServiceClient, opts ListOpts) (p pagination.Pager) { 56 q, err := opts.ToRepositoryListQuery() 57 if err != nil { 58 return pagination.Pager{Err: err} 59 } 60 61 // GET /v2/manage/repos 62 url := client.ServiceURL("manage", "repos") + q 63 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 64 return RepositoryPage{pagination.OffsetPageBase{PageResult: r}} 65 }) 66 } 67 68 type RepositoryPage struct { 69 pagination.OffsetPageBase 70 } 71 72 func ExtractRepositories(p pagination.Page) ([]ImageRepository, error) { 73 var res []ImageRepository 74 err := extract.IntoSlicePtr(p.(RepositoryPage).BodyReader(), &res, "") 75 return res, err 76 }