github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/apigw/v2/key/List.go (about) 1 package key 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 SignatureID string `q:"id"` 14 SignatureName string `q:"name"` 15 PreciseSearch string `q:"precise_search"` 16 } 17 18 func List(client *golangsdk.ServiceClient, opts ListOpts) ([]SignKeyResp, error) { 19 q, err := golangsdk.BuildQueryString(&opts) 20 if err != nil { 21 return nil, err 22 } 23 pages, err := pagination.Pager{ 24 Client: client, 25 InitialURL: client.ServiceURL("apigw", "instances", opts.GatewayID, "signs") + q.String(), 26 CreatePage: func(r pagination.NewPageResult) pagination.NewPage { 27 return SignatureKeyPage{NewSinglePageBase: pagination.NewSinglePageBase{NewPageResult: r}} 28 }, 29 }.NewAllPages() 30 31 if err != nil { 32 return nil, err 33 } 34 return ExtractSignatureKey(pages) 35 } 36 37 type SignatureKeyPage struct { 38 pagination.NewSinglePageBase 39 } 40 41 func ExtractSignatureKey(r pagination.NewPage) ([]SignKeyResp, error) { 42 var s struct { 43 SignatureKeys []SignKeyResp `json:"signs"` 44 } 45 err := extract.Into(bytes.NewReader((r.(SignatureKeyPage)).Body), &s) 46 return s.SignatureKeys, err 47 }