forked from TrueCloudLab/distribution
81c21411e8
This changeset provides a common http handler for serving errcodes. This should unify http responses across webservices in the face of errors. Several type assertions have been added, as well, to ensure the error interface is implemented. Signed-off-by: Stephen J Day <stephen.day@docker.com>
17 lines
383 B
Go
17 lines
383 B
Go
package handlers
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
// closeResources closes all the provided resources after running the target
|
|
// handler.
|
|
func closeResources(handler http.Handler, closers ...io.Closer) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
for _, closer := range closers {
|
|
defer closer.Close()
|
|
}
|
|
handler.ServeHTTP(w, r)
|
|
})
|
|
}
|