File tree 3 files changed +33
-0
lines changed
3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -50,3 +50,8 @@ pipeline:
50
50
commands :
51
51
- cd sqlkit
52
52
- go build
53
+ httpmiddleware-build :
54
+ image : golang:1.9.2
55
+ commands :
56
+ - cd httpmiddleware
57
+ - go build
Original file line number Diff line number Diff line change
1
+ package httpmiddleware
2
+
3
+ import "net/http"
4
+
5
+ func RecoverInternalServerError (handler http.Handler ) http.HandlerFunc {
6
+ return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
7
+ defer func () {
8
+ r := recover ()
9
+ if r != nil {
10
+ w .WriteHeader (http .StatusInternalServerError )
11
+ w .Write ([]byte ("Internal server error" ))
12
+ }
13
+ }()
14
+ handler .ServeHTTP (w , r )
15
+ })
16
+ }
Original file line number Diff line number Diff line change
1
+ package httpmiddleware
2
+
3
+ import "net/http"
4
+
5
+ // `Use` allows us to stack middleware to process the request
6
+ // Example taken from https://github.com/gorilla/mux/pull/36#issuecomment-25849172
7
+ func Use (handler http.HandlerFunc , mid ... func (http.Handler ) http.HandlerFunc ) http.HandlerFunc {
8
+ for _ , m := range mid {
9
+ handler = m (handler )
10
+ }
11
+ return handler
12
+ }
You can’t perform that action at this time.
0 commit comments