package routes import ( "basic-sensor-receiver/app" "net/http" "github.com/gin-gonic/gin" ) type postLoginBody struct { Username string `json:"username" binding:"required"` Password string `json:"password" binding:"required"` } func Login(s *app.Server) gin.HandlerFunc { return func(c *gin.Context) { body := postLoginBody{} if err := bindJSONBodyOrAbort(c, &body); err != nil { return } if body.Password != s.Config.AuthPassword || body.Username != s.Config.AuthUsername { c.AbortWithStatus(401) return } if err := s.Services.Auth.Login(c); err != nil { c.AbortWithError(500, err) } c.Writer.WriteHeader(http.StatusOK) } } func Logout(s *app.Server) gin.HandlerFunc { return func(c *gin.Context) { if err := s.Services.Auth.Logout(c); err != nil { c.AbortWithError(500, err) } c.Writer.WriteHeader(http.StatusOK) } }