以下是我運(yùn)行的代碼,問(wèn)題是我得到404頁(yè)面沒(méi)有找到而不是graphql游樂(lè)場(chǎng)頁(yè)面是否可以使用gqlgen的httprouter,或者我需要回到chi或mux我也無(wú)法使用中間件,因?yàn)閞沒(méi)有使用方法package mainimport ( "gographql-server/graph" "gographql-server/graph/generated" "log" "net/http" "os" "github.com/99designs/gqlgen/graphql/handler" "github.com/99designs/gqlgen/graphql/playground" "github.com/julienschmidt/httprouter")const defaultPort = "8080"func PlaygroundHandler() httprouter.Handle { h := playground.Handler("GraphQL", "/query") return func(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { h.ServeHTTP(w, req) }}func GraphqlHandler() httprouter.Handle { h := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}})) return func(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { h.ServeHTTP(w, req) }}func main() { port := os.Getenv("PORT") if port == "" { port = defaultPort } r := httprouter.New() r.POST("/query", GraphqlHandler()) r.GET("/", PlaygroundHandler()) // r.Use(middleware.RequestID) // r.Use(middleware.Logger) // r.Use(middleware.Recoverer) // r.Use(middlewares.AuthMiddleware()) log.Printf("connect to http://localhost:%s/ for GraphQL playground", port) log.Fatal(http.ListenAndServe(":"+port, nil))}
404 頁(yè)面在嘗試將 Gqlgen 與朱利安施密特/http 路由器一起使用時(shí)未找到
阿波羅的戰(zhàn)車(chē)
2022-09-19 17:20:30