github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/bss/v2/orders/results.go (about) 1 package orders 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/huaweicloud/golangsdk" 8 ) 9 10 type UnsubscribeResult struct { 11 golangsdk.Result 12 } 13 14 type Order struct { 15 ErrorCode string `json:"error_code"` 16 ErrorMsg string `json:"error_msg"` 17 OrderIDs []string `json:"order_ids"` 18 } 19 20 func (r UnsubscribeResult) Extract() (*Order, error) { 21 var response Order 22 err := r.ExtractInto(&response) 23 return &response, err 24 } 25 26 type GetResult struct { 27 golangsdk.Result 28 } 29 30 type OrderStatus struct { 31 ErrorCode string `json:"error_code"` 32 ErrorMsg string `json:"error_msg"` 33 OrderInfo OrderInfo `json:"order_info"` 34 } 35 36 type OrderInfo struct { 37 Status int `json:"status"` 38 } 39 40 func (r GetResult) Extract() (*OrderStatus, error) { 41 var response OrderStatus 42 err := r.ExtractInto(&response) 43 return &response, err 44 } 45 46 func WaitForOrderSuccess(client *golangsdk.ServiceClient, secs int, orderID string) error { 47 return golangsdk.WaitFor(secs, func() (bool, error) { 48 order := new(OrderStatus) 49 _, err := client.Get(getURL(client, orderID), &order, nil) 50 if err != nil { 51 return false, err 52 } 53 time.Sleep(15 * time.Second) 54 55 if order.OrderInfo.Status == 5 { 56 return true, nil 57 } 58 if order.OrderInfo.Status == 4 { 59 err = fmt.Errorf("Order canceled: %s.", orderID) 60 return false, err 61 } 62 63 return false, nil 64 }) 65 }