Перенести решение лабораторной 1 как основу для лабораторной 2
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package httpx
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const keyUserID = "messenger.user_id"
|
||||
|
||||
// SetUserID records the identified caller for the handlers behind the
|
||||
// identification middleware and for the access log. It lives here rather
|
||||
// than in the auth package because the access log needs it and auth already
|
||||
// depends on this package.
|
||||
func SetUserID(c *gin.Context, id uuid.UUID) {
|
||||
c.Set(keyUserID, id)
|
||||
}
|
||||
|
||||
func UserID(c *gin.Context) (uuid.UUID, bool) {
|
||||
v, ok := c.Get(keyUserID)
|
||||
if !ok {
|
||||
return uuid.Nil, false
|
||||
}
|
||||
id, ok := v.(uuid.UUID)
|
||||
return id, ok
|
||||
}
|
||||
Reference in New Issue
Block a user