File tree 4 files changed +31
-0
lines changed
4 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -9,4 +9,5 @@ require (
9
9
github.com/jmoiron/sqlx v1.3.5 // indirect
10
10
github.com/lib/pq v1.10.6 // indirect
11
11
github.com/satori/go.uuid v1.2.0 // indirect
12
+ github.com/sirupsen/logrus v1.8.1 // indirect
12
13
)
Original file line number Diff line number Diff line change @@ -967,6 +967,7 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
967
967
github.com/sirupsen/logrus v1.4.2 /go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE =
968
968
github.com/sirupsen/logrus v1.6.0 /go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88 =
969
969
github.com/sirupsen/logrus v1.7.0 /go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0 =
970
+ github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE =
970
971
github.com/sirupsen/logrus v1.8.1 /go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0 =
971
972
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d /go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc =
972
973
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a /go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA =
@@ -1392,6 +1393,7 @@ golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBc
1392
1393
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d /go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg =
1393
1394
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e /go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg =
1394
1395
golang.org/x/sys v0.0.0-20220111092808-5a964db01320 /go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg =
1396
+ golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf h1:Fm4IcnUL803i92qDlmB0obyHmosDrxZWxJL3gIeNqOw =
1395
1397
golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf /go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg =
1396
1398
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 /go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw =
1397
1399
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 /go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo =
Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ func NewHandler(service CommentService) *Handler {
25
25
h .Router = mux .NewRouter ()
26
26
h .mapRoutes ()
27
27
28
+ h .Router .Use (JSONMiddleware )
29
+ h .Router .Use (LoggingMiddleware )
30
+
28
31
h .Server = & http.Server {
29
32
Addr : "0.0.0.0:8080" ,
30
33
Handler : h .Router ,
Original file line number Diff line number Diff line change
1
+ package http
2
+
3
+ import (
4
+ "net/http"
5
+
6
+ log "github.com/sirupsen/logrus"
7
+ )
8
+
9
+ func JSONMiddleware (next http.Handler ) http.Handler {
10
+ return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
11
+ w .Header ().Set ("Content-Type" , "application/json; charset=UTF-8" )
12
+
13
+ next .ServeHTTP (w , r )
14
+ })
15
+ }
16
+
17
+ func LoggingMiddleware (next http.Handler ) http.Handler {
18
+ return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
19
+ log .WithFields (
20
+ log.Fields {
21
+ "method" : r .Method ,
22
+ "path" : r .URL .Path ,
23
+ }).Info ("handled request" )
24
+ })
25
+ }
You can’t perform that action at this time.
0 commit comments