2016-03-22 61 views
1

我已經開始學習最近lang lang。我花了幾個小時,但無法弄清楚這有什麼問題。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[:])) 

}

以下錯誤拋出語法錯誤:意外的名字,期待) 它可能是簡單的,但我在圍棋郎知識有限我無法弄清楚。

+1

爲什麼在調用UserPrefer時你有類型名稱'int64'和'string'? – Michael

+0

在什麼位置拋出錯誤? – AJPennster

+0

@AjPennster。在代碼中我提到編譯時錯誤。任何投票原因? – deadman

回答

2

先生您呼叫的方法

使用

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

代替

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

時,儘管調用函數只是傳遞的參數傳遞的類型。您不需要傳遞參數的類型。

相關問題