第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

GoLang 上的反射錯誤 - 參數(shù)太少

GoLang 上的反射錯誤 - 參數(shù)太少

Go
一只萌萌小番薯 2021-09-10 15:34:15
我有這個控制器:package webimport (    "net/http")func init() {}func (controller *Controller) Index(r *http.Request) (string, int) {    return "Testing", http.StatusOK}使用此處理程序:type Application struct {}func (application *Application) Route(controller interface{}, route string) http.HandlerFunc {    return func(w http.ResponseWriter, r *http.Request) {        var ptr reflect.Value        var value reflect.Value        var finalMethod reflect.Value        value = reflect.ValueOf(controller)        // if we start with a pointer, we need to get value pointed to        // if we start with a value, we need to get a pointer to that value        if value.Type().Kind() == reflect.Ptr {            ptr = value            value = ptr.Elem()        } else {            ptr = reflect.New(reflect.TypeOf(controller))            temp := ptr.Elem()            temp.Set(value)        }        // check for method on value        method := value.MethodByName(route)        if method.IsValid() {            finalMethod = method        }        // check for method on pointer        method = ptr.MethodByName(route)        if method.IsValid() {            finalMethod = method             }    }}它是這樣執(zhí)行的:controller := &web.Controller{}application := &system.Application{}http.HandleFunc("/", application.Route(controller, "Index"))問題是它編譯好了。它沒有顯示任何錯誤,但是當(dāng)我訪問該網(wǎng)站時,只需指向 localhost,它就會顯示:2014/12/27 22:38:16 http: panic serving 127.0.0.1:58304: reflect: Call with too few input argumentsgoroutine 20 [running]:net/http.func·011()    /usr/local/Cellar/go/1.3.3/libexec/src/pkg/net/http/server.go:1100 +0xb7我找不到任何錯誤,更奇怪的是它編譯正常......我是 Go 新手,所以我不知道發(fā)生了什么......
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 182 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號