Skip to content

Commit 30826e0

Browse files
committed
feat(std-http): accept Mux as interface instead of *http.ServeMux
1 parent fdf32da commit 30826e0

6 files changed

Lines changed: 41 additions & 16 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ type ServerInterface interface {
650650
GetPing(w http.ResponseWriter, r *http.Request)
651651
}
652652

653-
func HandlerFromMux(si ServerInterface, m *http.ServeMux) http.Handler {
653+
func HandlerFromMux(si ServerInterface, m Mux) http.Handler {
654654
return HandlerWithOptions(si, StdHTTPServerOptions{
655655
BaseRouter: m,
656656
})

examples/authenticated-api/stdhttp/api/api.gen.go

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/minimal-server/stdhttp/api/ping.gen.go

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/petstore-expanded/stdhttp/api/petstore.gen.go

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/test/strict-server/stdhttp/server.gen.go

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/codegen/templates/stdhttp/std-http-handler.tmpl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,26 @@ func Handler(si ServerInterface) http.Handler {
33
return HandlerWithOptions(si, StdHTTPServerOptions{})
44
}
55

6+
type Mux interface {
7+
HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
8+
ServeHTTP(w http.ResponseWriter, r *http.Request)
9+
}
10+
611
type StdHTTPServerOptions struct {
712
BaseURL string
8-
BaseRouter *http.ServeMux
13+
BaseRouter Mux
914
Middlewares []MiddlewareFunc
1015
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
1116
}
1217

1318
// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.
14-
func HandlerFromMux(si ServerInterface, m *http.ServeMux) http.Handler {
19+
func HandlerFromMux(si ServerInterface, m Mux) http.Handler {
1520
return HandlerWithOptions(si, StdHTTPServerOptions {
1621
BaseRouter: m,
1722
})
1823
}
1924

20-
func HandlerFromMuxWithBaseURL(si ServerInterface, m *http.ServeMux, baseURL string) http.Handler {
25+
func HandlerFromMuxWithBaseURL(si ServerInterface, m Mux, baseURL string) http.Handler {
2126
return HandlerWithOptions(si, StdHTTPServerOptions {
2227
BaseURL: baseURL,
2328
BaseRouter: m,

0 commit comments

Comments
 (0)