Subrouters? #102
Answered
by
vearutop
peterkuykendall
asked this question in
Q&A
Subrouters?
#102
-
Could you show an example with subrouters? Looks like chi's Mount isn't supported? |
Beta Was this translation helpful? Give feedback.
Answered by
vearutop
Dec 1, 2022
Replies: 1 comment 1 reply
-
Hello, please check https://github.com/swaggest/rest/blob/master/_examples/mount/main.go if it fits your case. service := web.DefaultService()
service.OpenAPI.Info.Title = "Security and Mount Example"
apiV1 := web.DefaultService()
apiV1.Wrap(
middleware.BasicAuth("Admin Access", map[string]string{"admin": "admin"}),
nethttp.HTTPBasicSecurityMiddleware(service.OpenAPICollector, "Admin", "Admin access"),
)
apiV1.Post("/sum", sum())
apiV1.Post("/mul", mul())
service.Mount("/api/v1", apiV1)
service.Docs("/api/v1/docs", swgui.New)
// Blanket handler, for example to serve static content.
service.Mount("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("blanket handler got a request: " + r.URL.String()))
})) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
peterkuykendall
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, please check https://github.com/swaggest/rest/blob/master/_examples/mount/main.go if it fits your case.