diff --git a/pkg/rabbit/connection.go b/pkg/rabbit/connection.go index 2fba784..50620ee 100644 --- a/pkg/rabbit/connection.go +++ b/pkg/rabbit/connection.go @@ -75,25 +75,21 @@ func (c *Connection) listenCloseNotify() { )) for { - select { - case <-c.closeNotify: - c.logger.Info("Trying to reconnect to rabbit") + <-c.closeNotify + c.logger.Info("Trying to reconnect to rabbit") - dial, dialErr := amqp.Dial(c.connString) - if dialErr != nil { - c.logger.Error("Error during reconnect try - ", dialErr) + dial, dialErr := amqp.Dial(c.connString) + if dialErr != nil { + c.logger.Error("Error during reconnect try - ", dialErr) - continue - } - - c.conn = dial - c.closeNotify = dial.NotifyClose(make(chan *amqp.Error)) - - c.logger.Info("Rabbit connection stabilized") - - break + continue } + c.conn = dial + c.closeNotify = dial.NotifyClose(make(chan *amqp.Error)) + + c.logger.Info("Rabbit connection stabilized") + time.Sleep(c.reconnectInterval) } } diff --git a/router/midlleware/user.go b/router/midlleware/user.go index b41575e..2c922e1 100644 --- a/router/midlleware/user.go +++ b/router/midlleware/user.go @@ -9,6 +9,12 @@ import ( "github.com/gin-gonic/gin" ) +type ContextKey string + +const ( + UserContextKey ContextKey = "user" +) + func SetUserFromJWT() gin.HandlerFunc { return func(c *gin.Context) { ctx := c.Request.Context() @@ -34,7 +40,7 @@ func SetUserFromJWT() gin.HandlerFunc { return } - ctx = context.WithValue(ctx, "user", user) + ctx = context.WithValue(ctx, UserContextKey, user) c.Request = c.Request.WithContext(ctx)