亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

通話中沒有足夠的參數

通話中沒有足夠的參數

Go
智慧大石 2021-10-04 18:15:13
我正在嘗試創建一個顯示用戶 IP 的 go 應用程序。我無法弄清楚我的日志控制臺錯誤:go:14: 沒有足夠的參數調用 getJsonRes去應用代碼:package mainimport (    "encoding/json"    "net/http"    "fmt")type Addrs struct {    ip string}func handler(w http.ResponseWriter, r *http.Request) {    response, err := getJsonRes()    if err != nil {    http.Error(w, err.Error(), http.StatusInternalServerError)    return    }    w.Header().Set("Content-Type", "application/json")    fmt.Fprintf(w, string(response))}func main() {    http.HandleFunc("/", handler)}func getJsonRes(r *http.Request)([]byte, error ) {    ip := Addrs{ r.RemoteAddr }    return json.MarshalIndent(ip, "", " ")}
查看完整描述

1 回答

?
藍山帝景

TA貢獻1843條經驗 獲得超7個贊

你的職能

func getJsonRes(r *http.Request)([]byte, error )

接受一個請求指針并返回一個字節數組和/或一個錯誤。

在這條線上

response, err := getJsonRes()

你不帶參數調用它。您可能打算執行以下操作

response, err := getJsonRes(r)


查看完整回答
反對 回復 2021-10-04
  • 1 回答
  • 0 關注
  • 195 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號