mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
33 lines
630 B
Go
33 lines
630 B
Go
package controllers
|
|
|
|
import (
|
|
"github.com/crawlab-team/crawlab/core/constants"
|
|
"github.com/crawlab-team/crawlab/core/interfaces"
|
|
"github.com/crawlab-team/crawlab/core/models/models/v2"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func GetUserFromContext(c *gin.Context) (u interfaces.User) {
|
|
value, ok := c.Get(constants.UserContextKey)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
u, ok = value.(interfaces.User)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return u
|
|
}
|
|
|
|
func GetUserFromContextV2(c *gin.Context) (u *models.UserV2) {
|
|
value, ok := c.Get(constants.UserContextKey)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
u, ok = value.(*models.UserV2)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return u
|
|
}
|