首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Softlayer GO lang库:卷的下单问题

Softlayer GO lang库:卷的下单问题
EN

Stack Overflow用户
提问于 2016-11-23 14:49:40
回答 1查看 80关注 0票数 0

我正在使用SoftLayer GO API客户端库从link https://github.com/softlayer/softlayer-go订购耐力卷

我遇到了PlaceOrder API的问题。

请查看下面的错误消息:

2016/11/22 23:54:51调试路径:SoftLayer 2016/11/22 23:54:51调试参数:{"parameters":{"ComplexType":"SoftLayer_Container_Product_Order"}} 2016/11/22 23:54:51调试响应:{“error”:“属性'ComplexType‘对'SoftLayer_Container_Product_Order’无效。”,"code":"SoftLayer_Exception_Public"} SoftLayer_Exception_Public:属性'ComplexType‘对’SoftLayer_Container_Product_Order‘无效。(HTTP 500)

我已经为ComplexType属性赋予了正确的值。

EN

回答 1

Stack Overflow用户

发布于 2016-11-24 00:39:48

好吧,我不知道你的代码,但我能够使verifyOrder工作,以订购耐力卷

代码语言:javascript
复制
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,我也不知道如何打印响应的所有属性,所以我只打印了一个property.As你可能是GO的专家我相信你可以改进代码。

注意:请确保您在订单中使用了正确的价格。

我在Go中的代码基本上与RESTFul调用相同,如下所示:

代码语言:javascript
复制
{
  "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
    }
  ]
}

问候

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40757800

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档