github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/apigw/v2/tr_specials/List.go (about) 1 package special_policy 2 3 import ( 4 "bytes" 5 6 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 7 "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" 8 "github.com/opentelekomcloud/gophertelekomcloud/pagination" 9 ) 10 11 type ListOpts struct { 12 GatewayID string `json:"-"` 13 ThrottleID string `json:"-"` 14 ObjectType string `q:"object_type"` 15 AppName string `q:"app_name"` 16 User string `q:"user"` 17 } 18 19 func List(client *golangsdk.ServiceClient, opts ListOpts) ([]ThrottlingResp, error) { 20 q, err := golangsdk.BuildQueryString(&opts) 21 if err != nil { 22 return nil, err 23 } 24 pages, err := pagination.Pager{ 25 Client: client, 26 InitialURL: client.ServiceURL("apigw", "instances", opts.GatewayID, "throttles", 27 opts.ThrottleID, "throttle-specials") + q.String(), 28 CreatePage: func(r pagination.NewPageResult) pagination.NewPage { 29 return ThrottlingPage{NewSinglePageBase: pagination.NewSinglePageBase{NewPageResult: r}} 30 }, 31 }.NewAllPages() 32 33 if err != nil { 34 return nil, err 35 } 36 return ExtractTrPolicy(pages) 37 } 38 39 type ThrottlingPage struct { 40 pagination.NewSinglePageBase 41 } 42 43 func ExtractTrPolicy(r pagination.NewPage) ([]ThrottlingResp, error) { 44 var s struct { 45 ThrottlingPolicies []ThrottlingResp `json:"throttle_specials"` 46 } 47 err := extract.Into(bytes.NewReader((r.(ThrottlingPage)).Body), &s) 48 return s.ThrottlingPolicies, err 49 }