無法從Go 中的GetConfiguration API 呼叫檢索項目類別資訊
REST API 呼叫
GET https://api.softlayer.com/rest/v3/SoftLayer_Product_Package/257/getConfiguration?objectMask=mask[itemCategory]
{ "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 } }
package main import ( "fmt" "encoding/json" "github.com/softlayer/softlayer-go/session" "github.com/softlayer/softlayer-go/services" ) func main() { username := "set-me" apikey := "set-me" sess := session.New(username, apikey) sess.Debug = true service := services.GetProductPackageService(sess) mask := "itemCategory" result, err := service.Mask(mask).Id(257).GetConfiguration() if err != nil { fmt.Printf("\n Unable to retrieve config:\n - %s\n", err) return } jsonFormat, jsonErr := json.MarshalIndent(result, "", " ") if jsonErr != nil { fmt.Println(jsonErr) return } fmt.Println(string(jsonFormat)) }
Sample entry: { "id": 7167, "isRequired": 0, "itemCategoryId": 390, "orderStepId": 1, "packageId": 257, "sort": 0 }
範例輸出顯示itemCategory 欄位未填充,儘管已包含在物件中遮罩:
解決方案:sess := session.New(username, apikey)
endpoint := "https://api.softlayer.com/rest/v3" sess := session.New(username, apikey, endpoint)
以上是儘管在物件遮罩中指定了,但為什麼在 Go 中使用 GetConfiguration API 呼叫時 itemCategory 欄位為空?的詳細內容。更多資訊請關注PHP中文網其他相關文章!