Mask and filter are not working when using the Sof

2019-07-08 11:13发布

问题:

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:

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