24 lines
342 B
Go
24 lines
342 B
Go
package handler
|
|
|
|
import "github.com/gin-gonic/gin"
|
|
|
|
func userID(c *gin.Context) uint {
|
|
id, exists := c.Get("user_id")
|
|
if !exists {
|
|
return 0
|
|
}
|
|
uid, ok := id.(uint)
|
|
if !ok {
|
|
return 0
|
|
}
|
|
return uid
|
|
}
|
|
|
|
func isAdmin(c *gin.Context) bool {
|
|
role, exists := c.Get("role")
|
|
if !exists {
|
|
return false
|
|
}
|
|
return role.(string) == "admin"
|
|
}
|