我正在将值从 JSON 编组到结构中。这是我的结构:
type AutoGenerated struct {
ID int64 `json:"id"`
SuccessHTTPResponseCode int `json:"success_http_response_code"`
MaxRetries int `json:"max_retries"`
CallbackWebhookURL string `json:"callback_webhook_url"`
Request struct {
URL string `json:"url"` (error occurs here)
Method string `json:"method"`
HTTPHeaders struct {
ContentType string `json:"content-Type"`
Accept string `json:"accept"`
} `json:"http_headers"`
Body struct {
Foo string `json:"foo"`
} `json:"body"`
} `json:"request"`
}
下面是我编组它的函数:
func createBSON() []byte {
data1:= AutoGenerated{
ID: 1462406556741,
SuccessHTTPResponseCode: 200,
MaxRetries: 3,
CallbackWebhookURL: "http://requestb.in/vh61ztvh",
Request: {
URL: "http://requestb.in/vh61ztvh",
Method: "POST",
HTTPHeaders: {
ContentType: "Application/json",
Accept: "Application/json",
},
Body : {
Foo: "bar",
},
},
}
sample,err:=json.Marshal(data1)
check(err)
fmt.Print(sample)
return sample
}
我做了一些更改,以上是我更新的功能。我收到以下错误:
missing type in composite literal
我对 Golang 有点陌生。我无法弄清楚这个错误是什么。任何帮助,将不胜感激。
holdtom
MYYA
相关分类