package handler import ( "esforum/pkg/util" "net/http" "github.com/gin-gonic/gin" ) const ( authorizationHeader = "Authorization" userCtx = "UserInfo" userHeader = "UserHeader" ) func (h *Handler) userIdentity(c *gin.Context) { header := c.GetHeader(authorizationHeader) if header == "" { util.NewErrorResponse(c, http.StatusUnauthorized, "empty auth header") return } user, err := h.services.Authorization.Authorize(header) if err != nil { util.NewErrorResponse(c, http.StatusUnauthorized, err.Error()) } c.Set(userCtx, user.Id) c.Set(userHeader, header) }