getuid.go 349 B

1234567891011121314151617
  1. package unity
  2. import (
  3. "github.com/gin-gonic/gin"
  4. )
  5. func GetUId(c *gin.Context) (id int, name, role string) {
  6. value, exists := c.Get("user")
  7. if exists {
  8. users := value.(map[string]interface{})
  9. id = int(users["ID"].(float64))
  10. name = users["username"].(string)
  11. role = users["role"].(string)
  12. return id, name, role
  13. }
  14. return 0, "", ""
  15. }