-
Notifications
You must be signed in to change notification settings - Fork 0
/
gomiddleware.go
91 lines (68 loc) · 2.41 KB
/
gomiddleware.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package gomiddleware
import (
"net/http"
"github.com/MrAndreID/golog"
helpers "github.com/MrAndreID/gohelpers"
)
func Log(next http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
golog.Info("Accepted")
golog.Info("[" + request.Method + "] " + request.Host + request.URL.String())
next(response, request)
golog.Info("Closing")
})
}
func Acceptable(next http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
if request.Header["Accept"] == nil || request.Header["Accept"][0] == "" {
helpers.HandleResponse(response, 406, "not acceptable", nil)
return
}
next(response, request)
})
}
func ClientID(next http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
if request.Header["Client-Id"] == nil || request.Header["Client-Id"][0] == "" {
helpers.HandleResponse(response, 400, "client id not found", nil)
return
}
next(response, request)
})
}
func Timestamp(next http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
if request.Header["Timestamp"] == nil || request.Header["Timestamp"][0] == "" {
helpers.HandleResponse(response, 400, "timestamp not found", nil)
return
}
next(response, request)
})
}
func AppID(next http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
if request.Header["App-Id"] == nil || request.Header["App-Id"][0] == "" {
helpers.HandleResponse(response, 400, "app id not found", nil)
return
}
next(response, request)
})
}
func PrivateKey(next http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
if request.Header["Private-Key"] == nil || request.Header["Private-Key"][0] == "" {
helpers.HandleResponse(response, 400, "private key not found", nil)
return
}
next(response, request)
})
}
func ContentType(next http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
if request.Header["Content-Type"] == nil || request.Header["Content-Type"][0] == "" {
helpers.HandleResponse(response, 400, "content type not found", nil)
return
}
next(response, request)
})
}