github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/apigw/v2/api/List.go (about)

     1  package api
     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  	ID            string `json:"id"`
    14  	GroupID       string `q:"group_id"`
    15  	ReqProtocol   string `q:"req_protocol"`
    16  	ReqMethod     string `q:"req_method"`
    17  	ReqUri        string `q:"req_uri"`
    18  	AuthType      string `q:"auth_type"`
    19  	PreciseSearch string `q:"precise_search"`
    20  	EnvID         string `q:"env_id"`
    21  	Type          int    `q:"type"`
    22  	Name          string `q:"name"`
    23  }
    24  
    25  func List(client *golangsdk.ServiceClient, opts ListOpts) ([]ApiResp, error) {
    26  	q, err := golangsdk.BuildQueryString(&opts)
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  	pages, err := pagination.Pager{
    31  		Client:     client,
    32  		InitialURL: client.ServiceURL("apigw", "instances", opts.GatewayID, "apis") + q.String(),
    33  		CreatePage: func(r pagination.NewPageResult) pagination.NewPage {
    34  			return EnvPage{NewSinglePageBase: pagination.NewSinglePageBase{NewPageResult: r}}
    35  		},
    36  	}.NewAllPages()
    37  
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  	return ExtractEnvs(pages)
    42  }
    43  
    44  type EnvPage struct {
    45  	pagination.NewSinglePageBase
    46  }
    47  
    48  func ExtractEnvs(r pagination.NewPage) ([]ApiResp, error) {
    49  	var s struct {
    50  		Gateways []ApiResp `json:"apis"`
    51  	}
    52  	err := extract.Into(bytes.NewReader((r.(EnvPage)).Body), &s)
    53  	return s.Gateways, err
    54  }