我最近开始学习Go lang。我花了几个小时,但不知道这有什么问题。
这是我的代码:
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[:]))
}
以下错误是抛出语法错误:意外名称,期望) 这可能很简单,但由于我对 Go 语言的了解有限,我无法弄清楚。
潇潇雨雨
慕沐林林
慕盖茨4494581
相关分类