github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v1/eips/results.go (about) 1 package eips 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 //ApplyResult is a struct which represents the result of apply public ip 9 type ApplyResult struct { 10 golangsdk.Result 11 } 12 13 func (r ApplyResult) Extract() (PublicIp, error) { 14 var ipResp struct { 15 IP PublicIp `json:"publicip"` 16 OrderID string `json:"order_id"` 17 PublicipID string `json:"publicip_id"` 18 } 19 err := r.Result.ExtractInto(&ipResp) 20 if ipResp.PublicipID != "" { 21 ipResp.IP.ID = ipResp.PublicipID 22 } 23 if ipResp.OrderID != "" { 24 ipResp.IP.OrderID = ipResp.OrderID 25 } 26 27 return ipResp.IP, err 28 } 29 30 //PublicIp is a struct that represents a public ip 31 type PublicIp struct { 32 ID string `json:"id"` 33 Status string `json:"status"` 34 Type string `json:"type"` 35 PublicAddress string `json:"public_ip_address"` 36 PrivateAddress string `json:"private_ip_address"` 37 PortID string `json:"port_id"` 38 TenantID string `json:"tenant_id"` 39 OrderID string `json:"order_id"` 40 CreateTime string `json:"create_time"` 41 BandwidthID string `json:"bandwidth_id"` 42 BandwidthSize int `json:"bandwidth_size"` 43 BandwidthShareType string `json:"bandwidth_share_type"` 44 EnterpriseProjectID string `json:"enterprise_project_id"` 45 } 46 47 //GetResult is a return struct of get method 48 type GetResult struct { 49 golangsdk.Result 50 } 51 52 func (r GetResult) Extract() (PublicIp, error) { 53 var getResp struct { 54 IP PublicIp `json:"publicip"` 55 } 56 err := r.Result.ExtractInto(&getResp) 57 return getResp.IP, err 58 } 59 60 //DeleteResult is a struct of delete result 61 type DeleteResult struct { 62 golangsdk.ErrResult 63 } 64 65 //UpdateResult is a struct which contains the result of update method 66 type UpdateResult struct { 67 golangsdk.Result 68 } 69 70 func (r UpdateResult) Extract() (PublicIp, error) { 71 var ip PublicIp 72 err := r.Result.ExtractIntoStructPtr(&ip, "publicip") 73 return ip, err 74 } 75 76 type PublicIPPage struct { 77 pagination.LinkedPageBase 78 } 79 80 func (r PublicIPPage) NextPageURL() (string, error) { 81 publicIps, err := ExtractPublicIPs(r) 82 if err != nil { 83 return "", err 84 } 85 return r.WrapNextPageURL(publicIps[len(publicIps)-1].ID) 86 } 87 88 func ExtractPublicIPs(r pagination.Page) ([]PublicIp, error) { 89 var s struct { 90 PublicIPs []PublicIp `json:"publicips"` 91 } 92 err := r.(PublicIPPage).ExtractInto(&s) 93 return s.PublicIPs, err 94 } 95 96 // IsEmpty checks whether a NetworkPage struct is empty. 97 func (r PublicIPPage) IsEmpty() (bool, error) { 98 s, err := ExtractPublicIPs(r) 99 return len(s) == 0, err 100 }