douhan8581 2018-02-17 16:25
浏览 56
已采纳

使用SoftLayer API时,遮罩和滤镜不起作用

When I add billingItemFlag to my mask and filter it is missing in the results. I am using the SoftLayer-go api from the SoftLayer GitHub account. Is my filter or mask wrong?

Please consider the following code:

const mask string = "id;hostname;domain;billingItemFlag;billingItem"
var filters = filter.Build(
    filter.Path("billingItemFlag").NotNull(),
    filter.Path("billingItem").NotNull(),
)
accountService := services.GetAccountService(softlayerSession)
hardware, err := accountService.Filter(filters).Mask(mask).Limit(1).GetHardware()
if err != nil {
    panic(err)
}
println(hardware[0].BillingItemFlag)

The result of this code is "0x0" which is an invalid memory address.

When I enable debugging I can see the fields are not being returned but domain, hostname, and others are.

2018/02/17 11:08:08 ->>>Request:
2018/02/17 11:08:08 POST /xmlrpc/v3.1/SoftLayer_Account HTTP/1.1
Host: api.softlayer.com
User-Agent: Go-http-client/1.1
Content-Length: 1875
Content-Type: text/xml
Accept-Encoding: gzip

<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>getHardware</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>REMOVED</string></value></member><member><name>apiKey</name><value><string>REMOVED</string></value></member></struct></value></member><member><name>SoftLayer_AccountObjectMask</name><value><struct><member><name>mask</name><value><struct><member><name>hostname</name><value><array><data></data></array></value></member><member><name>domain</name><value><array><data></data></array></value></member><member><name>billingItemFlag</name><value><array><data></data></array></value></member><member><name>billingItem</name><value><struct><member><name>recurringFee</name><value><array><data></data></array></value></member></struct></value></member><member><name>id</name><value><array><data></data></array></value></member></struct></value></member></struct></value></member><member><name>SoftLayer_AccountObjectFilter</name><value><struct><member><name>billingItem</name><value><struct><member><name>operation</name><value><string>not null</string></value></member></struct></value></member><member><name>billingItemFlag</name><value><struct><member><name>operation</name><value><string>not null</string></value></member></struct></value></member></struct></value></member><member><name>resultLimit</name><value><struct><member><name>limit</name><value><int>1</int></value></member><member><name>offset</name><value><int>0</int></value></member></struct></value></member></struct></value></member></struct></value></param></params></methodCall>
2018/02/17 11:08:09 

<<<-Response:
2018/02/17 11:08:09 HTTP/1.1 200 OK
Connection: close
Cache-Control: private
Content-Type: text/xml
Date: Sat, 17 Feb 2018 16:08:08 GMT
Ntcoent-Length: 3031
Server: Apache
Softlayer-Total-Items: 402
Vary: Accept-Encoding
X-Frame-Options: SAMEORIGIN

<?xml version="1.0" encoding="utf-8"?>
<params>
<param>
 <value>
  <struct>
   <member>
    <name>accountId</name>
    <value>
     <int>REMOVED</int>
    </value>
   </member>
   <member>
    <name>bareMetalInstanceFlag</name>
    <value>
     <int>0</int>
    </value>
   </member>
   <member>
    <name>domain</name>
    <value>
     <string>REMOVED</string>
    </value>
   </member>
   <member>
    <name>fullyQualifiedDomainName</name>
    <value>
     <string>REMOVED</string>
    </value>
   </member>
   <member>
    <name>hardwareStatusId</name>
    <value>
     <int>5</int>
    </value>
   </member>
   <member>
    <name>hostname</name>
    <value>
     <string>REMOVED</string>
    </value>
   </member>
   <member>
    <name>id</name>
    <value>
     <int>REMOVED</int>
    </value>
   </member>
   <member>
    <name>manufacturerSerialNumber</name>
    <value>
     <string>REMOVED</string>
    </value>
   </member>
   <member>
    <name>notes</name>
    <value>
     <string/>
    </value>
   </member>
   <member>
    <name>provisionDate</name>
    <value>
     <stringREMOVED</string>
    </value>
   </member>
   <member>
    <name>serialNumber</name>
    <value>
     <string> REMOVED</string>
    </value>
   </member>
   <member>
    <name>serviceProviderId</name>
    <value>
     <int>1</int>
    </value>
   </member>
   <member>
    <name>serviceProviderResourceId</name>
    <value>
     <string/>
    </value>
   </member>
   <member>
    <name>globalIdentifier</name>
    <value>
     <string> REMOVED </string>
    </value>
   </member>
   <member>
    <name>networkManagementIpAddress</name>
    <value>
     <string>1 REMOVED 0</string>
    </value>
   </member>
   <member>
    <name>primaryBackendIpAddress</name>
    <value>
     <string> REMOVED 4</string>
    </value>
   </member>
   <member>
    <name>primaryIpAddress</name>
    <value>
     <string> REMOVED </string>
    </value>
   </member>
   <member>
    <name>privateIpAddress</name>
    <value>
     <string> REMOVED</string>
    </value>
   </member>
   <member>
    <name>hardwareFunction</name>
    <value>
     <struct>
      <member>
       <name>code</name>
       <value>
        <string>WEBSVR</string>
       </value>
      </member>
      <member>
       <name>description</name>
       <value>
        <string>Web Server</string>
       </value>
      </member>
      <member>
       <name>id</name>
       <value>
        <int>3</int>
       </value>
      </member>
     </struct>
    </value>
   </member>
   <member>
    <name>hardwareStatus</name>
    <value>
     <struct>
      <member>
       <name>id</name>
       <value>
        <int>5</int>
       </value>
      </member>
      <member>
       <name>status</name>
       <value>
        <string>ACTIVE</string>
       </value>
      </member>
     </struct>
    </value>
   </member>
  </struct>
 </value>
</param>
</params>
  • 写回答

1条回答 默认 最新

  • doujiepin5547 2018-02-19 20:32
    关注

    The code you posted works when using the default endpoint or any other REST endpoint. It seems an issue from API, I recommend to switch to the default endpoint or use:

    https://api.softlayer.com/rest/v3.1

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 视频编码 十六进制问题
  • ¥15 Xsheii7我安装这个文件的时候跳出来另一个文件已锁定文件的无一部分进程无法访问。这个该怎么解决
  • ¥15 unity terrain打包后地形错位,跟建筑不在同一个位置,怎么办
  • ¥15 FileNotFoundError 解决方案
  • ¥15 uniapp实现如下图的图表功能
  • ¥15 u-subsection如何修改相邻两个节点样式
  • ¥30 vs2010开发 WFP(windows filtering platform)
  • ¥15 服务端控制goose报文控制块的发布问题
  • ¥15 学习指导与未来导向啊
  • ¥15 求多普勒频移瞬时表达式