WIP: Develop #1

Draft
ostiwe wants to merge 10 commits from dev into main
2 changed files with 18 additions and 16 deletions
Showing only changes of commit 465eb99bae - Show all commits

View File

@@ -75,25 +75,21 @@ func (c *Connection) listenCloseNotify() {
)) ))
for { for {
select { <-c.closeNotify
case <-c.closeNotify: c.logger.Info("Trying to reconnect to rabbit")
c.logger.Info("Trying to reconnect to rabbit")
dial, dialErr := amqp.Dial(c.connString) dial, dialErr := amqp.Dial(c.connString)
if dialErr != nil { if dialErr != nil {
c.logger.Error("Error during reconnect try - ", dialErr) c.logger.Error("Error during reconnect try - ", dialErr)
continue continue
}
c.conn = dial
c.closeNotify = dial.NotifyClose(make(chan *amqp.Error))
c.logger.Info("Rabbit connection stabilized")
break
} }
c.conn = dial
c.closeNotify = dial.NotifyClose(make(chan *amqp.Error))
c.logger.Info("Rabbit connection stabilized")
time.Sleep(c.reconnectInterval) time.Sleep(c.reconnectInterval)
} }
} }

View File

@@ -9,6 +9,12 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
type ContextKey string
const (
UserContextKey ContextKey = "user"
)
func SetUserFromJWT() gin.HandlerFunc { func SetUserFromJWT() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
ctx := c.Request.Context() ctx := c.Request.Context()
@@ -34,7 +40,7 @@ func SetUserFromJWT() gin.HandlerFunc {
return return
} }
ctx = context.WithValue(ctx, "user", user) ctx = context.WithValue(ctx, UserContextKey, user)
c.Request = c.Request.WithContext(ctx) c.Request = c.Request.WithContext(ctx)