github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/natgateways/results.go (about)

     1  package natgateways
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // NatGateway is a struct that represents a nat gateway
     9  type NatGateway struct {
    10  	ID                  string `json:"id"`
    11  	Name                string `json:"name"`
    12  	Description         string `json:"description"`
    13  	RouterID            string `json:"router_id"`
    14  	InternalNetworkID   string `json:"internal_network_id"`
    15  	TenantID            string `json:"tenant_id"`
    16  	Spec                string `json:"spec"`
    17  	Status              string `json:"status"`
    18  	AdminStateUp        bool   `json:"admin_state_up"`
    19  	EnterpriseProjectID string `json:"enterprise_project_id"`
    20  }
    21  
    22  // GetResult is a return struct of get method
    23  type GetResult struct {
    24  	golangsdk.Result
    25  }
    26  
    27  func (r GetResult) Extract() (NatGateway, error) {
    28  	var NatGW NatGateway
    29  	err := r.Result.ExtractIntoStructPtr(&NatGW, "nat_gateway")
    30  	return NatGW, err
    31  }
    32  
    33  // CreateResult is a return struct of create method
    34  type CreateResult struct {
    35  	golangsdk.Result
    36  }
    37  
    38  func (r CreateResult) Extract() (NatGateway, error) {
    39  	var NatGW NatGateway
    40  	err := r.Result.ExtractIntoStructPtr(&NatGW, "nat_gateway")
    41  	return NatGW, err
    42  }
    43  
    44  // UpdateResult is a return struct of update method
    45  type UpdateResult struct {
    46  	golangsdk.Result
    47  }
    48  
    49  func (r UpdateResult) Extract() (NatGateway, error) {
    50  	var NatGW NatGateway
    51  	err := r.Result.ExtractIntoStructPtr(&NatGW, "nat_gateway")
    52  	return NatGW, err
    53  }
    54  
    55  // DeleteResult is a return struct of delete method
    56  type DeleteResult struct {
    57  	golangsdk.ErrResult
    58  }
    59  
    60  type NatGatewayPage struct {
    61  	pagination.LinkedPageBase
    62  }
    63  
    64  func (r NatGatewayPage) NextPageURL() (string, error) {
    65  	var s struct {
    66  		Links []golangsdk.Link `json:"nat_gateways_links"`
    67  	}
    68  	err := r.ExtractInto(&s)
    69  	if err != nil {
    70  		return "", err
    71  	}
    72  	return golangsdk.ExtractNextURL(s.Links)
    73  }
    74  
    75  func (r NatGatewayPage) IsEmpty() (bool, error) {
    76  	is, err := ExtractNatGateways(r)
    77  	return len(is) == 0, err
    78  }
    79  
    80  func ExtractNatGateways(r pagination.Page) ([]NatGateway, error) {
    81  	var s struct {
    82  		NatGateways []NatGateway `json:"nat_gateways"`
    83  	}
    84  	err := (r.(NatGatewayPage)).ExtractInto(&s)
    85  	return s.NatGateways, err
    86  }