r.Handle的参数中的http.Handler值:缺少方法ServeHTTP错误

问题描述

我试图在Go中使用大猩猩mux构建基本的Web API。这是我的代码。请帮助我了解一些界面在这里的工作方式。

func main() {
    r := mux.NewRouter()

    r.Handle("/",http.FileServer(http.Dir("./views/")))
    r.PathPrefix("/static/").Handler(http.StripPrefix("/static/",http.FileServer(http.Dir("./static/"))))

    r.Handle("/status",myHandler).Methods("GET")

    http.ListenAndServe(":8080",r)

}

func myHandler(w http.ResponseWriter,r *http.Request) {
    w.WriteHeader(http.StatusOK)

} ```


error :- `cannot use myHandler (value of type func(w http.ResponseWriter,r *http.Request)) as http.Handler value in argument to r.Handle: missing method ServeHTTP `

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)