Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chi : Change the signature of the MiddlewareFunc for compatibilities. #578

Merged
merged 1 commit into from May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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