我们正在使用openapi-generator来生成go-gin-server.这将生成包含类型*interface{}
的属性的模型,例如.
type Material struct {
Id *interface{} `json:"id,omitempty"`
Reference *interface{} `json:"reference,omitempty"`
}
如果我有一个没有指针的 struct 实例,如何设置这些指针呢?我try 了以下几种方法:
theReturnId := "abc123"
material.Id = &theReturnId
这会产生以下编译错误:
不能将&;theReturnID(*字符串类型的值)用作赋值中的*接口{}值:*字符串不实现*接口{}(类型interface{} is pointer to interface, not interface)
theReturnId := "abc123"
*material.Id = theReturnId
这会产生一个运行时错误,即指针为零.
我试过很多其他的方法,但都没有用.我错过了什么吗?谢谢!