-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterceptor.go
59 lines (46 loc) · 1.27 KB
/
interceptor.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
47
48
49
50
51
52
53
54
55
56
57
58
59
package callx
import (
"fmt"
"github.com/valyala/fasthttp"
)
type headerInterceptor struct {
Header Header
}
func (a *headerInterceptor) Response(res *fasthttp.Response) {
}
func (a *headerInterceptor) Request(req *fasthttp.Request) {
for k, v := range a.Header {
req.Header.Set(k, v)
}
}
type loggerInterceptor struct {
}
func (l *loggerInterceptor) Response(res *fasthttp.Response) {
}
func (l *loggerInterceptor) Request(req *fasthttp.Request) {
fmt.Println("-->", string(req.Header.Method()), string(req.Header.RequestURI()))
fmt.Println("-->", req.Header.RawHeaders())
fmt.Println("-->", "END")
}
type jsonContentTypeInterceptor struct {
}
func (j *jsonContentTypeInterceptor) Response(res *fasthttp.Response) {
}
func (j *jsonContentTypeInterceptor) Request(req *fasthttp.Request) {
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
}
// HeaderInterceptor provide a instance
func HeaderInterceptor(header Header) Interceptor {
return &headerInterceptor{
Header: header,
}
}
// JSONContentTypeInterceptor provide a instance
func JSONContentTypeInterceptor() Interceptor {
return &jsonContentTypeInterceptor{}
}
// LoggerInterceptor provide a instance
func LoggerInterceptor() Interceptor {
return &loggerInterceptor{}
}