86ffe515df
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>
18 lines
383 B
Go
18 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)
|
|
})
|
|
}
|