对于以下代码:
import (
"github.com/go-openapi/runtime/middleware"
"github.com/gorilla/mux"
)
m := mux.NewRouter()
// handlers for API
getRouter := m.Methods(http.MethodGet).Subrouter()
getRouter.HandleFunc("/v1/items", someHandler.ListAll)
// handler for documentation
opts := middleware.RedocOpts{SpecURL: "/swagger.yaml"}
sh := middleware.Redoc(opts, nil)
getRouter.Handle("/docs", sh)
getRouter.Handle("/swagger.yaml", http.FileServer(http.Dir("./")))
http://localhost:8080/docs
&http://localhost:8080/swagger.yaml
呈现文档。Api 处理程序在 uri 上也可以正常工作/v1/items
为 http://localhost:8080/v1/docs
&http://localhost:8080/v1/swagger.yaml
以下呈现文档是所做的更改:
m := mux.NewRouter()
// handlers for API
getRouter := m.Methods(http.MethodGet).PathPrefix("/v1").Subrouter()
getRouter.HandleFunc("/items", someHandler.ListAll)
// handler for documentation
opts := middleware.RedocOpts{SpecURL: "/swagger.yaml",BasePath: "/v1"}
sh := middleware.Redoc(opts, nil)
getRouter.Handle("/docs", sh)
getRouter.Handle("/swagger.yaml", http.FileServer(http.Dir("./")))
但不起作用。api 处理程序和文档处理程序都失败了
如何在 http://localhost:8080/v1/docs
&上呈现文档http://localhost:8080/v1/swagger.yaml
?
如何渲染api http://localhost:8080/v1/items
?随着路径前缀的变化