Go语言无法在返回参数中使用r(类型*mux.Router)作为类型*mux.Route
嗨,我在其他Go文件中初始化路由器,并在主文件中返回它的引用,然后在主文件中初始化服务器。 这段代码没有编译Go语言无法在返回参数中使用r(类型*mux.Router)作为类型*mux.Route,go,servemux,Go,Servemux,嗨,我在其他Go文件中初始化路由器,并在主文件中返回它的引用,然后在主文件中初始化服务器。 这段代码没有编译 package router import ( "github.com/gorilla/mux" "binapp/controllers" ) const all_bin string = "/bin" func InitRouter() (*mux.Route) { r := mux.NewRouter().StrictSlash(true) r
package router
import (
"github.com/gorilla/mux"
"binapp/controllers"
)
const all_bin string = "/bin"
func InitRouter() (*mux.Route) {
r := mux.NewRouter().StrictSlash(true)
r.HandleFunc(all_bin, controllers.BinController)
return r
}
package main
import (
"binapp/router"
"log"
"net/http"
)
func main() {
router := router.InitRouter()
log.Fatal(http.ListenAndServe(":9096", router))
}
我得到的错误如下:
# binapp/router
binapp/router/Route.go:15: cannot use r (type *mux.Router) as type *mux.Route in return argument
InitRouter
的返回类型错误。返回*mux.Route
,但指定返回类型为*mux.Route
初始化路由器的返回类型错误。您返回一个*mux.Route
,但指定返回类型为*mux.Route
Y在这个地球上我确实犯了那个错误。我现在把自己锁在浴室里一个小时了。我真的犯了那个错误。我现在把自己锁在浴室里一个小时。