From 433a19a2dbe424bf4a28ef6b0f14a0ae231bb0e1 Mon Sep 17 00:00:00 2001 From: celogeek Date: Sat, 5 Feb 2022 11:23:56 +0100 Subject: [PATCH] set restriction, fix print --- internal/photos/api/main.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/photos/api/main.go b/internal/photos/api/main.go index b0539ef..e9f3359 100644 --- a/internal/photos/api/main.go +++ b/internal/photos/api/main.go @@ -2,7 +2,6 @@ package api import ( "context" - "errors" "log" "math/rand" "net/http" @@ -49,14 +48,15 @@ func New(logger *log.Logger, config *ServiceConfig) *Service { func (s *Service) SetupRoutes() { s.Gin.Use(gin.Logger()) s.Gin.Use(s.Recovery) + s.Gin.Use(s.RequireBody) ac := s.Gin.Group("/account") ac.POST("/signup", s.Signup) ac.POST("/login", s.Login) - ac.POST("/logout", s.Logout) + ac.GET("/logout", s.RequireSession, s.Logout) s.Gin.NoRoute(func(c *gin.Context) { - s.Error(c, http.StatusNotFound, errors.New("this route doesn't exists")) + s.Error(c, http.StatusNotFound, ErrReqNotFound) }) } @@ -84,7 +84,7 @@ func (s *Service) Run() error { // a timeout of 5 seconds. signal.Notify(quit, os.Interrupt) <-quit - s.Logger.Println("shutdown ...") + s.Logger.Print("shutdown ...") ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -96,11 +96,11 @@ func (s *Service) Run() error { if err != nil { return err } - s.Logger.Println("closing database ...") + s.Logger.Print("closing database ...") if err := db.Close(); err != nil { return err } - s.Logger.Println("exiting") + s.Logger.Print("exiting") return runError }