-
Notifications
You must be signed in to change notification settings - Fork 17
/
handle.go
32 lines (24 loc) · 1.06 KB
/
handle.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
package mps
import "net/http"
type Handle interface {
RequestHandle
ResponseHandle
}
type RequestHandle interface {
HandleRequest(req *http.Request, ctx *Context) (*http.Request, *http.Response)
}
// A wrapper that would convert a function to a RequestHandle interface type
type RequestHandleFunc func(req *http.Request, ctx *Context) (*http.Request, *http.Response)
// RequestHandle.Handle(req, ctx) <=> RequestHandleFunc(req, ctx)
func (f RequestHandleFunc) HandleRequest(req *http.Request, ctx *Context) (*http.Request, *http.Response) {
return f(req, ctx)
}
type ResponseHandle interface {
HandleResponse(resp *http.Response, err error, ctx *Context) (*http.Response, error)
}
// A wrapper that would convert a function to a ResponseHandle interface type
type ResponseHandleFunc func(resp *http.Response, err error, ctx *Context) (*http.Response, error)
// ResponseHandle.Handle(resp, ctx) <=> ResponseHandleFunc(resp, ctx)
func (f ResponseHandleFunc) HandleResponse(resp *http.Response, err error, ctx *Context) (*http.Response, error) {
return f(resp, err, ctx)
}