Golang (v1.8) - Error: type *mux.Route has no field or method Method
Golang (v1.8) - Error: type *mux.Route has no field or method Method
我有一个 go/golang 应用程序配备了大猩猩工具包。我正在尝试使用 gorilla/mux 包进行路由。我的路线和错误信息如下。有什么指点吗?
路线
`
r := mux.NewRouter()
r.HandleFunc("/", landing)
r.HandleFunc("/contact", contact)
r.HandleFunc("/faq", faq)
r.HandleFunc("/register", accountsC.New).Method("GET")
r.HandleFunc("/register", accountsC.Create).Method("POST")
http.ListenAndServe(":8080", r)`
我收到了这个错误:
# command-line-arguments
./main.go:27: r.HandleFunc("/register", accountsC.New).Method undefined
(type *mux.Route has no field or method Method)
./main.go:28: r.HandleFunc("/register", accountsC.Create).Method undefined
(type *mux.Route has no field or method Method)
没有方法Method
,需要使用Methods
没有method方法,需要使用Methods
应该是这样
r := mux.NewRouter()
r.HandleFunc("/", landing)
r.HandleFunc("/contact", contact)
r.HandleFunc("/faq", faq)
r.HandleFunc("/register", accountsC.New).Methods("GET")
r.HandleFunc("/register", accountsC.Create).Methods("POST")
http.ListenAndServe(":8080", r)
我有一个 go/golang 应用程序配备了大猩猩工具包。我正在尝试使用 gorilla/mux 包进行路由。我的路线和错误信息如下。有什么指点吗?
路线 `
r := mux.NewRouter()
r.HandleFunc("/", landing)
r.HandleFunc("/contact", contact)
r.HandleFunc("/faq", faq)
r.HandleFunc("/register", accountsC.New).Method("GET")
r.HandleFunc("/register", accountsC.Create).Method("POST")
http.ListenAndServe(":8080", r)`
我收到了这个错误:
# command-line-arguments
./main.go:27: r.HandleFunc("/register", accountsC.New).Method undefined
(type *mux.Route has no field or method Method)
./main.go:28: r.HandleFunc("/register", accountsC.Create).Method undefined
(type *mux.Route has no field or method Method)
没有方法Method
,需要使用Methods
没有method方法,需要使用Methods 应该是这样
r := mux.NewRouter()
r.HandleFunc("/", landing)
r.HandleFunc("/contact", contact)
r.HandleFunc("/faq", faq)
r.HandleFunc("/register", accountsC.New).Methods("GET")
r.HandleFunc("/register", accountsC.Create).Methods("POST")
http.ListenAndServe(":8080", r)