Commit 4737a8d 1 parent 7aa2b60 commit 4737a8d Copy full SHA for 4737a8d
File tree 5 files changed +13
-4
lines changed
5 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -37,5 +37,5 @@ func main() {
37
37
}
38
38
39
39
router := routes .InitRouter ()
40
- log .Fatal (http .ListenAndServe (":" + os .Getenv ("PORT" ), router ))
40
+ log .Fatal (http .ListenAndServe (":" + os .Getenv ("PORT" ), & router ))
41
41
}
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ func InitDatabase(config DBConfig) *Database {
39
39
database .SetMaxIdleConns (4 )
40
40
41
41
// check if database is available
42
- if err := db .Ping (); err != nil {
42
+ if err := database .Ping (); err != nil {
43
43
log .Fatal (err )
44
44
}
45
45
Original file line number Diff line number Diff line change
1
+ package routes
2
+
3
+ type ErrorResponse struct {
4
+ Message string `json:"message"`
5
+ }
Original file line number Diff line number Diff line change 1
1
package routes
2
2
3
3
import (
4
+ "encoding/json"
4
5
"log"
5
6
"net/http"
6
7
)
@@ -24,7 +25,10 @@ func HeaderBinding(next http.Handler) http.Handler {
24
25
25
26
if r .Method == "POST" {
26
27
if r .Header .Get ("Content-Type" ) != "application/json" {
27
- log .Fatal ("Wrong Content-Type in POST request. application/json expected" )
28
+ _ = json .NewEncoder (w ).Encode (ErrorResponse {
29
+ "Wrong Content-Type in POST request. application/json expected" ,
30
+ })
31
+ return
28
32
}
29
33
}
30
34
Original file line number Diff line number Diff line change 4
4
"github.com/gorilla/mux"
5
5
)
6
6
7
- func InitRouter () (router * mux.Router ) {
7
+ func InitRouter () (router mux.Router ) {
8
8
router .Use (RequestLogger , HeaderBinding )
9
9
router .HandleFunc ("/users/auth/new" , registerUser ).Methods ("POST" )
10
10
router .HandleFunc ("/users/auth" , loginUser ).Methods ("POST" )
You can’t perform that action at this time.
0 commit comments