dpl22899 2016-03-22 11:18
浏览 39
已采纳

GO lang语法错误:意外的名称,应为)

I have started learning Go lang recently.I have spend couple of hours but can't figure out what's wrong with this.

Here is my code:

func preference(cc *core.ComponentContext, w http.ResponseWriter, req *http.Request){

userID, err := core.PostParam(req, "user_id")
key, err := core.PostParam(req, "key")
value, err := core.PostParam(req, "value")  
if err != nil {
    cc.Error("Error reading the user id:", err.Error())
    msg := fmt.Sprintf("user_id: %s", err.Error())
    http.Error(w, msg, http.StatusBadRequest)
    return
}

response :=models.UserPrefer(cc, userID int64, key string, value string) --> compile time error

b, err := json.Marshal(response)
if err != nil {
    http.Error(w, "Internal Error", http.StatusInternalServerError)
    return
}
fmt.Fprintf(w, string(b[:]))

}

Following error is throw syntax error: unexpected name, expecting ) it's probably simple, but with my limited knowledge in Go lang I can't figure out.

  • 写回答

3条回答 默认 最新

  • duancenxiao0482 2016-03-22 11:51
    关注

    You are passing types when calling methods

    Use

    response :=models.UserPrefer(cc, userID, key, value)
    

    instead of

    response :=models.UserPrefer(cc, userID int64, key string, value string)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作