github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/networking/v2/extensions/natgateways/results.go (about) 1 package natgateways 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/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 } 20 21 // GetResult is a return struct of get method 22 type GetResult struct { 23 golangsdk.Result 24 } 25 26 func (r GetResult) Extract() (NatGateway, error) { 27 var natGw NatGateway 28 err := r.Result.ExtractIntoStructPtr(&natGw, "nat_gateway") 29 return natGw, err 30 } 31 32 // CreateResult is a return struct of create method 33 type CreateResult struct { 34 golangsdk.Result 35 } 36 37 func (r CreateResult) Extract() (NatGateway, error) { 38 var NatGW NatGateway 39 err := r.Result.ExtractIntoStructPtr(&NatGW, "nat_gateway") 40 return NatGW, err 41 } 42 43 // UpdateResult is a return struct of update method 44 type UpdateResult struct { 45 golangsdk.Result 46 } 47 48 func (r UpdateResult) Extract() (NatGateway, error) { 49 var natGw NatGateway 50 err := r.Result.ExtractIntoStructPtr(&natGw, "nat_gateway") 51 return natGw, err 52 } 53 54 // DeleteResult is a return struct of delete method 55 type DeleteResult struct { 56 golangsdk.ErrResult 57 } 58 59 type NatGatewayPage struct { 60 pagination.LinkedPageBase 61 } 62 63 func (r NatGatewayPage) NextPageURL() (string, error) { 64 var s struct { 65 Links []golangsdk.Link `json:"nat_gateways_links"` 66 } 67 err := r.ExtractInto(&s) 68 if err != nil { 69 return "", err 70 } 71 return golangsdk.ExtractNextURL(s.Links) 72 } 73 74 func (r NatGatewayPage) IsEmpty() (bool, error) { 75 is, err := ExtractNatGateways(r) 76 return len(is) == 0, err 77 } 78 79 func ExtractNatGateways(r pagination.Page) ([]NatGateway, error) { 80 var s struct { 81 NatGateways []NatGateway `json:"nat_gateways"` 82 } 83 err := (r.(NatGatewayPage)).ExtractInto(&s) 84 return s.NatGateways, err 85 }