-3
我的结构是这样的如何初始化嵌套结构?
type A struct{
B struct{
C interface{} `json:"c"`
}
}
type C struct{
D string `json:"d"`
E string `json:"e"`
}
利用这个结构是这样的方式,
func someFunc(){
var x A
anotherFunc(&x)
}
func anotherFunc(obj interface{}){
// resp.Body has this {D: "123", E: "xyx"}
return json.NewDecoder(resp.Body).Decode(obj)
}
,我必须初始化它的单元测试,我这样做,
x := &A{
B: {
C : map[string]interface{}{
D: 123,
E: xyx,
},
},
}
但得到错误missing type in composite literal
,我做错了什么?
我尝试的方式解释说,它仍然没有工作,它会显示'不能使用结构{C接口}文字(类型结构{C接口{}}类型结构{C接口{}})*一些奇怪的错误*字段值中' –