diff --git a/internal/photos/api/check_body.go b/internal/photos/api/check_body.go deleted file mode 100644 index f28ce80..0000000 --- a/internal/photos/api/check_body.go +++ /dev/null @@ -1,19 +0,0 @@ -package photosapi - -import ( - "errors" - "net/http" - - "github.com/gin-gonic/gin" -) - -var ( - ErrReqMissingBody = errors.New("missing body") -) - -func (s *Service) RequireBody(c *gin.Context) { - if c.Request.Method == "POST" && c.Request.ContentLength == 0 { - c.AbortWithError(http.StatusBadRequest, ErrReqMissingBody) - return - } -} diff --git a/internal/photos/api/default.go b/internal/photos/api/default.go new file mode 100644 index 0000000..3810a33 --- /dev/null +++ b/internal/photos/api/default.go @@ -0,0 +1,8 @@ +package photosapi + +import "github.com/gin-gonic/gin" + +func (s *Service) DefaultJSON(c *gin.Context) { + c.Header("content-type", "application/json; charset=utf-8") + c.Next() +} diff --git a/internal/photos/api/main.go b/internal/photos/api/main.go index 7c3fc7a..88b344b 100644 --- a/internal/photos/api/main.go +++ b/internal/photos/api/main.go @@ -52,8 +52,8 @@ func (s *Service) SetupRoutes() { s.Gin.Use( gin.Logger(), s.Recovery, + s.DefaultJSON, s.HandleError, - s.RequireBody, ) s.AccountInit()