Skip to content

Commit

Permalink
Change the signature of the MiddlewareFunc for chi, getting more comp…
Browse files Browse the repository at this point in the history
…atibilities with another libraries. (#578)
  • Loading branch information
uhey22e committed May 26, 2022
1 parent b3eedde commit b027708
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
26 changes: 13 additions & 13 deletions examples/petstore-expanded/chi/api/petstore.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 31 additions & 31 deletions internal/test/server/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pkg/codegen/templates/chi/chi-middleware.tmpl
Expand Up @@ -5,7 +5,7 @@ type ServerInterfaceWrapper struct {
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}

type MiddlewareFunc func(http.HandlerFunc) http.HandlerFunc
type MiddlewareFunc func(http.Handler) http.Handler

{{range .}}{{$opid := .OperationId}}

Expand Down Expand Up @@ -168,15 +168,15 @@ func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Requ
{{end}}
{{end}}

var handler = func(w http.ResponseWriter, r *http.Request) {
var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.{{.OperationId}}(w, r{{genParamNames .PathParams}}{{if .RequiresParamObject}}, params{{end}})
}
})

for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}

handler(w, r.WithContext(ctx))
handler.ServeHTTP(w, r.WithContext(ctx))
}
{{end}}

Expand Down

0 comments on commit b027708

Please sign in to comment.