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

GO lang语法错误:意外名称,应为),go,Go,我最近开始学习围棋。我花了几个小时,但不知道这有什么问题 这是我的代码: 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"

我最近开始学习围棋。我花了几个小时,但不知道这有什么问题

这是我的代码:

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 lang的了解有限,我无法理解。

在调用方法时,您正在传递类型

使用

而不是

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

调用函数时,只需传递参数。您不需要传递参数的类型

当我在实例化一个类型时忘记输入冒号时,我得到了一个与此非常类似的错误。创建了一个最低限度的示例来说明

prog.go:11:12:语法错误:意外的文字“detacient”,应为逗号或}

在本例中,我只需要在属性名后添加一个冒号

r := Rock{
    RockType:   "Sedimentary", // the ":" was missing, and is in the go play link above
}

我得到这个错误是因为我使用了
保留的
关键字作为方法的参数名

引发此错误的代码段:

func setCustomTypeData(set bson.M, type string) {

}
修复此问题的代码段:

func setCustomTypeData(set bson.M, customManagedType string) {

}

为什么在对
userpreference
的调用中有类型名
int64
string
?在哪一行抛出错误?@AjPennster。在代码中,我提到了编译时错误。有没有否决投票的理由?不要删掉你的问题所涉及的错误。如果其他人读到这篇文章,答案和评论将不再有意义。
func setCustomTypeData(set bson.M, customManagedType string) {

}