-
Notifications
You must be signed in to change notification settings - Fork 11
/
goa.go
46 lines (38 loc) · 997 Bytes
/
goa.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
40
41
42
43
44
45
46
package debug
import (
"net/http"
goahttp "goa.design/goa/v3/http"
)
// muxAdapter is a debug.Muxer adapter for goahttp.Muxer.
type muxAdapter struct {
muxer goahttp.Muxer
}
// HTTP methods supported by the adapter.
var httpMethods = []string{
http.MethodGet,
http.MethodHead,
http.MethodPost,
http.MethodPut,
http.MethodPatch,
http.MethodDelete,
http.MethodConnect,
http.MethodOptions,
http.MethodTrace,
}
// Adapt returns a debug.Muxer adapter for the given goahttp.Muxer.
func Adapt(m goahttp.Muxer) Muxer {
return muxAdapter{muxer: m}
}
func (m muxAdapter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
m.muxer.ServeHTTP(w, r)
}
func (m muxAdapter) Handle(path string, handler http.Handler) {
for _, method := range httpMethods {
m.muxer.Handle(method, path, handler.ServeHTTP)
}
}
func (m muxAdapter) HandleFunc(path string, handler func(http.ResponseWriter, *http.Request)) {
for _, method := range httpMethods {
m.muxer.Handle(method, path, handler)
}
}