mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-23 23:36:30 +00:00
26 lines
651 B
Go
26 lines
651 B
Go
|
package server
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
type HandlerFunc func(w http.ResponseWriter, r *http.Request) error
|
||
|
|
||
|
func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) error {
|
||
|
return f(w, r)
|
||
|
}
|
||
|
|
||
|
type Handler interface {
|
||
|
ServeHTTP(http.ResponseWriter, *http.Request) error
|
||
|
}
|
||
|
|
||
|
// ToHandler converts a function to a customer implementation of the Handler interface.
|
||
|
// that returns an error. This wrapper around the handler function and simply
|
||
|
// returns the nil in all cases
|
||
|
func ToHandler(handler http.Handler) Handler {
|
||
|
return HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
|
||
|
handler.ServeHTTP(w, r)
|
||
|
return nil
|
||
|
})
|
||
|
}
|