从golang调用时无法从调用GetConfiguration获取itemCategory信息 [英] Unable to get itemCategory info from call GetConfiguration when called from golang

查看:34
本文介绍了从golang调用时无法从调用GetConfiguration获取itemCategory信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

api调用

GET https://api.softlayer.com/rest/v3/SoftLayer_Product_Package/257/getConfiguration?objectMask=mask[itemCategory]

返回对象[]datatypes.Product_Package_Order_Configuration,其中已填充ItemCategory. 样本输出:

returns an object, []datatypes.Product_Package_Order_Configuration where ItemCategory is populated. sample output:

{
"id": 7167,
"isRequired": 0,
"itemCategoryId": 390,
"orderStepId": 1,
"packageId": 257,
"sort": 0,
"itemCategory": {
"categoryCode": "trusted_platform_module",
"id": 390,
"name": "Server Security",
"quantityLimit": 1,
"sortOrder": 0
}
},

当我尝试进行相同的调用时,即使在掩码中声明了itemCategory,也不会填充.请告知.

When I attempt the same call in go, itemCategory is not populated, even though I declare it in the mask. Please advise.

package main

import (
"fmt"
"github.com/softlayer/softlayer-go/services"
"github.com/softlayer/softlayer-go/session"
"encoding/json"
)

func main() {
    // SoftLayer API username and key
    username := "set-me"
    apikey   := "set-me"

    // Create a session
    sess := session.New(username, apikey)

    // Enable debug
    sess.Debug = true

    // Get SoftLayer_Account service
    service := services.GetProductPackageService(sess)

    // Object-Mask to get specific Vlan's information
    mask := "itemCategory"

    // Call to getNetworkVlans in order to retrieve vlans according to filter.
    result, err := service.Mask(mask).Id(257).GetConfiguration()
    if err != nil {
        fmt.Printf("\n Unable to retrieve config:\n - %s\n", err)
        return
    }

    // Following helps to print the result in json format.
    jsonFormat, jsonErr := json.MarshalIndent(result,"","     ")
    if jsonErr != nil {
        fmt.Println(jsonErr)
        return
    }
    fmt.Println(string(jsonFormat))
}

示例输出:

->>>Request:
2018/05/09 09:24:36 POST /xmlrpc/v3.1/SoftLayer_Product_Package HTTP/1.1
Host: api.softlayer.com
User-Agent: Go-http-client/1.1
Content-Length: 1055
Content-Type: text/xml
Accept-Encoding: gzip

<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>getConfiguration</methodName><params><param><value><struct><member><name>headers</name><value><struct><member><name>User-Agent</name><value><string>softlayer-go/v0.1.0-alpha (go1.9.2;amd64;darwin)</string></value></member><member><name>authenticate</name><value><struct><member><name>username</name><value><string>[[SL_USER]]</string></value></member><member><name>apiKey</name><value><string>[[SL_APIKEY]]</string></value></member></struct></value></member><member><name>SoftLayer_Product_PackageInitParameters</name><value><struct><member><name>id</name><value><int>257</int></value></member></struct></value></member><member><name>SoftLayer_Product_PackageObjectMask</name><value><struct><member><name>mask</name><value><struct><member><name>itemCategory</name><value><array><data></data></array></value></member></struct></value></member></struct></value></member></struct></value></member></struct></value></param></params></methodCall>
2018/05/09 09:24:36 


<<<-Response:
2018/05/09 09:24:36 HTTP/1.1 200 OK
Connection: close
Transfer-Encoding: chunked
Cache-Control: private
Content-Type: text/xml
Date: Wed, 09 May 2018 14:24:36 GMT
Server: Apache
Softlayer-Total-Items: 39
Strict-Transport-Security: max-age=31536000
Vary: Accept-Encoding
X-Frame-Options: SAMEORIGIN

然后返回具有与以下相同数据的html字符串 样本条目:

Then a string of html with the same data as below is returned Sample entry:

{
          "id": 7167,
          "isRequired": 0,
          "itemCategoryId": 390,
          "orderStepId": 1,
          "packageId": 257,
          "sort": 0
     },

推荐答案

默认端点是REST,但是在您的环境中,您使用的是xmlrpc,这可能是由于〜/.softlayer文件的存在,在这种情况下,配置为XMLRPC点.

The default endpoint is REST but in your environment you are using xmlrpc, which is probably due to the existence of the ~ / .softlayer file and in this it is configured as an XMLRPC enpoint.

有关更多信息,请参见以下文档: https://github.com/softlayer/softlayer-go

For more information you can see the following documentation: https://github.com/softlayer/softlayer-go

此问题发生在XMLRPC enpoint上,您可以在go GitHub中进行报告. https://github.com/softlayer/softlayer-go/issues/

This issue happens for the XMLRPC enpoint and you can report it in the go GitHub. https://github.com/softlayer/softlayer-go/issues/

使用REST端点尝试您的代码,例如以下示例:

Try in your code with the REST endpoint, like this example:

endpoint := "https://api.softlayer.com/rest/v3"

// Create a session
sess := session.New(username, apikey, endpoint)

这篇关于从golang调用时无法从调用GetConfiguration获取itemCategory信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆