forked from antchfx/antch
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmiddleware.go
More file actions
25 lines (20 loc) · 792 Bytes
/
middleware.go
File metadata and controls
25 lines (20 loc) · 792 Bytes
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
package antch
import (
"net/http"
)
// HttpMessageHandler is an interface that receives an HTTP request
// and returns an HTTP response.
type HttpMessageHandler interface {
Send(*http.Request) (*http.Response, error)
}
// Middleware is the HTTP message transport middle layer that send
// HTTP request passed one message Handler to the next message Handler
// until returns an HTTP response.
type Middleware func(HttpMessageHandler) HttpMessageHandler
// HttpMessageHandlerFunc is an adapter to allow the use of ordinary
// functions as HttpMessageHandler.
type HttpMessageHandlerFunc func(*http.Request) (*http.Response, error)
// Send sends a HTTP request and receives HTTP response.
func (f HttpMessageHandlerFunc) Send(req *http.Request) (*http.Response, error) {
return f(req)
}