0
鑑於以下代碼:使用地圖[字符串]接口{}:
type Message struct {
Params map[string]interface{} `json:"parameters"`
Result interface{} `json:"result"`
}
func (h Handler) Product(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
msg := &Message{
Action: "get_products",
Params: {
"id1": val1,
"id2": val2,
},
}
h.route(msg)
}
的想法是能夠發送一個未知量的一個塊ID1 => VAL1,ID2 => val2的...到路由。
它給了我這個錯誤:
missing type in composite literal
它是一個錯字,你的'Action'應是「結果」?或者它是你忘記在結構中定義的字段? – nevets