嗯,我不知道你的代码,但我能够让 verifyOrder 工作以订购耐力卷
package main
import (
"fmt"
//"log"
"github.com/softlayer/softlayer-go/datatypes"
"github.com/softlayer/softlayer-go/services"
"github.com/softlayer/softlayer-go/session"
"github.com/softlayer/softlayer-go/sl"
)
func main() {
sess := session.New() // See above for details about creating a new session
// Get the Virtual_Guest service
service := services.GetProductOrderService(sess)
// Create a Virtual_Guest struct as a template
vOrderTemplate := datatypes.Container_Product_Order_Network_Storage_Enterprise{}
vOrderTemplate.Location = sl.String("154820")
vOrderTemplate.Quantity = sl.Int(1)
vOrderTemplate.PackageId = sl.Int(240)
price1 := datatypes.Product_Item_Price{}
price1.Id = sl.Int(45058)
price2 := datatypes.Product_Item_Price{}
price2.Id = sl.Int(45098)
price3 := datatypes.Product_Item_Price{}
price3.Id = sl.Int(45068)
price4 := datatypes.Product_Item_Price{}
price4.Id = sl.Int(45118)
price5 := datatypes.Product_Item_Price{}
price5.Id = sl.Int(46120)
prices := []datatypes.Product_Item_Price{price1,price2,price3,price4,price5}
vOrderTemplate.Prices = prices
vOrderTemplate.OsFormatType = &datatypes.Network_Storage_Iscsi_OS_Type{
Id: sl.Int(12),
KeyName: sl.String("LINUX"),
}
vOrd, err := service.VerifyOrder(&vOrderTemplate)
if err != nil {
fmt.Printf("%s\n", err)
return
} else {
fmt.Printf("\norder verified with Total Recurring Tax %d\n", *vOrd.TotalRecurringTax)
}
}
我是 GO 新手,如果代码不是很简单,很抱歉:P,我也不知道如何打印响应的所有属性,所以我只打印了一个属性。你可能是专家在 GO 中我相信你可以改进代码。
请注意确保您在订单中使用正确的价格。
我在 Go 中的代码基本上和这样的 RESTFul 调用相同:
{
"parameters": [
{
"location": 154820, //Dallas 06
"packageId": 240,
"osFormatType": {
"id": 12,
"keyName": "LINUX"
},
"complexType": "SoftLayer_Container_Product_Order_Network_Storage_Enterprise",
"prices": [
{
"id": 45058 # Endurance Storage
},
{
"id": 45098 # Block Storage
},
{
"id": 45068 # 0.25 IOPS per GB
},
{
"id": 45118 # 20 GB Storage Space
},
{
"id": 46120 # 5 GB Storage Space - Snapshot
}
],
"quantity": 1
}
]
}
问候