GO lang 语法错误 : unexpected name, 期待)

标签 go

我最近开始学习 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 语言的了解有限,我无法弄清楚。

最佳答案

你在调用方法时传递类型

使用

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

代替

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

关于GO lang 语法错误 : unexpected name, 期待),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36152999/

相关文章:

go - 使用 go 设置 Web 服务器

循环中的 GO 例程 - 函数调用

go - 来自不同文件的全局变量 Golang

select - 从非 chan 类型 time.Duration 接收

go - 为什么不能转换 Slice 类型?

go - 使用带有 go/mgo 的嵌套结构进行部分更新

html - 如何使用 goquery 从 HTML 页面获取简单文本?

go - 使用未从包中导出的类型

go - 如何在GCP App Engine上使用自定义Go构建标记和工具?

go - 如何防止其他人更改返回结构的内容