为了账号安全,请及时绑定邮箱和手机立即绑定

使用 map[string]interface{} :

使用 map[string]interface{} :

Go
九州编程 2022-01-04 14:03:41
鉴于以下代码: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 ... 到 h.route。它给了我这个错误:复合文字中缺少类型
查看完整描述

1 回答

?
梦里花落0921

TA贡献1772条经验 获得超6个赞

你应该像这样初始化它:


func (h Handler) Product(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

    msg := &Message{

        Action: "get_products",

        Params: map[string]interface{}{

            "id1": val1,

            "id2": val2,

        },

    }

    h.route(msg)

}

精简编译:http : //play.golang.org/p/bXVOwIhLlg


查看完整回答
反对 回复 2022-01-04
  • 1 回答
  • 0 关注
  • 234 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号