For the below code:
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
renders the documentation. Api handler also works fine on uri /v1/items
To render documentation for http://localhost:8080/v1/docs
& http://localhost:8080/v1/swagger.yaml
below are the changes done:
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("./")))
but does not work. Both api handler & documentation handler fails
How to render documentation on http://localhost:8080/v1/docs
& http://localhost:8080/v1/swagger.yaml
?
How to render api on http://localhost:8080/v1/items
? With path prefix changes