File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 7
7
"time"
8
8
9
9
"bdo-rest-api/config"
10
+ "bdo-rest-api/middleware"
10
11
)
11
12
12
13
func ListenAndServe () {
@@ -20,10 +21,14 @@ func ListenAndServe() {
20
21
mux .HandleFunc ("GET /v1/guild/search" , getGuildSearch )
21
22
mux .HandleFunc ("/" , catchall )
22
23
24
+ middlewareStack := middleware .CreateStack (
25
+ middleware .SetHeaders ,
26
+ )
27
+
23
28
log .Println ("Listening for requests" )
24
29
srv := & http.Server {
25
30
Addr : fmt .Sprintf ("0.0.0.0:%v" , config .GetPort ()),
26
- Handler : mux ,
31
+ Handler : middlewareStack ( mux ) ,
27
32
IdleTimeout : 60 * time .Second ,
28
33
ReadTimeout : 15 * time .Second ,
29
34
WriteTimeout : 15 * time .Second ,
Original file line number Diff line number Diff line change
1
+ package middleware
2
+
3
+ import "net/http"
4
+
5
+ type Middleware func (http.Handler ) http.Handler
6
+
7
+ func CreateStack (xs ... Middleware ) Middleware {
8
+ return func (next http.Handler ) http.Handler {
9
+ for i := len (xs ) - 1 ; i >= 0 ; i -- {
10
+ x := xs [i ]
11
+ next = x (next )
12
+ }
13
+
14
+ return next
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments