开始 - 构建 POST 正文,收到错误 "invalid composite literal type string"
Go - building POST body, receive error "invalid composite literal type string"
我试图在 Go 中构建一个 POST 主体,但我不断收到以下错误:
无效的复合文字类型字符串
下面是我的代码和结构的片段,我不知道我做错了什么?
postData := projectPostData{
Filters: projectFilters{
Name: string{ // <-- Error is referred to on this line
target,
},
},
}
type projectPostData struct {
Filters projectFilters `json:"filters,omitempty"`
}
type projectFilters struct {
Name string `json:"name,omitempty"`
}
您可以查看以下代码:
package main
import(
"fmt"
)
type projectFilters struct {
Name string `json:"string,omitempty"`
}
type projectPostData struct {
Filters projectFilters `json:"filters,omitempty"`
}
func main(){
target := "test target"
postData := projectPostData{
Filters: projectFilters{
Name: target,
},
}
fmt.Println(postData)
}
我试图在 Go 中构建一个 POST 主体,但我不断收到以下错误:
无效的复合文字类型字符串
下面是我的代码和结构的片段,我不知道我做错了什么?
postData := projectPostData{
Filters: projectFilters{
Name: string{ // <-- Error is referred to on this line
target,
},
},
}
type projectPostData struct {
Filters projectFilters `json:"filters,omitempty"`
}
type projectFilters struct {
Name string `json:"name,omitempty"`
}
您可以查看以下代码:
package main
import(
"fmt"
)
type projectFilters struct {
Name string `json:"string,omitempty"`
}
type projectPostData struct {
Filters projectFilters `json:"filters,omitempty"`
}
func main(){
target := "test target"
postData := projectPostData{
Filters: projectFilters{
Name: target,
},
}
fmt.Println(postData)
}