mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 16:32:31 +01:00
20 lines
558 B
Go
20 lines
558 B
Go
package httperr
|
|
|
|
import "net/http"
|
|
|
|
// The HandlerFunc type is an adapter to allow the use of
|
|
// ordinary functions as HTTP handlers. If f is a function
|
|
// with the appropriate signature, HandlerFunc(f) is a
|
|
// Handler object that calls f.
|
|
type HandlerFunc func(http.ResponseWriter, *http.Request) error
|
|
|
|
// ServeHTTP calls f(w, r).
|
|
func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
if err := f(w, r); err != nil {
|
|
if v := r.Context().Value(onErrorIndex); v != nil {
|
|
v.(func(error))(err)
|
|
} else {
|
|
Write(w, r, err)
|
|
}
|
|
}
|
|
}
|