forked from HiFX/bingo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.go
39 lines (32 loc) · 774 Bytes
/
handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package bingo
import (
"io"
"net/http"
)
// Handler encapsulates the handlers
type Handler struct {
srv http.Handler
closers []io.Closer
}
// Close cleans up any resources
func (h *Handler) Close() error {
for _, cls := range h.closers {
if err := cls.Close(); err != nil {
return err
}
}
return nil
}
// AddCloser adds a closer
func (h *Handler) AddCloser(c io.Closer) *Handler {
h.closers = append(h.closers, c)
return h
}
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.srv.ServeHTTP(w, r)
}
//Wrap wraps http.Handler with the bingo Handler
func Wrap(h http.Handler) *Handler {
return &Handler{srv: h}
}
//TODO: check constants in https://github.com/labstack/echo/blob/a2d757eddc4d3bf17919d8e4b0a9b60743d38ecc/echo.go