redisService.go 916 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package service
  2. import (
  3. "github.com/mumushuiding/util"
  4. "github.com/go-workflow/go-workflow/workflow-engine/model"
  5. )
  6. // UserInfo 用户信息
  7. type UserInfo struct {
  8. Company string `json:"company"`
  9. // 用户所属部门
  10. Department string `json:"department"`
  11. Username string `json:"username"`
  12. ID string `json:"ID"`
  13. // 用户的角色
  14. Roles []string `json:"roles"`
  15. // 用户负责的部门
  16. Departments []string `json:"departments"`
  17. }
  18. // GetUserinfoFromRedis GetUserinfoFromRedis
  19. func GetUserinfoFromRedis(token string) (*UserInfo, error) {
  20. result, err := GetValFromRedis(token)
  21. if err != nil {
  22. return nil, err
  23. }
  24. // fmt.Println(result)
  25. var userinfo = &UserInfo{}
  26. err = util.Str2Struct(result, userinfo)
  27. if err != nil {
  28. return nil, err
  29. }
  30. return userinfo, nil
  31. }
  32. // GetValFromRedis 从redis获取值
  33. func GetValFromRedis(key string) (string, error) {
  34. return model.RedisGetVal(key)
  35. }