You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

accesstoken.go 826 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package accesstoken
  2. import (
  3. "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/accesstoken"
  4. "gitlink.org.cn/cloudream/jcs-pub/coordinator/internal/db"
  5. cortypes "gitlink.org.cn/cloudream/jcs-pub/coordinator/types"
  6. "gorm.io/gorm"
  7. )
  8. type ExitEvent = accesstoken.ExitEvent
  9. type CacheKey = accesstoken.CacheKey
  10. type Cache struct {
  11. *accesstoken.Cache
  12. db *db.DB
  13. }
  14. func New(db *db.DB) *Cache {
  15. c := &Cache{
  16. db: db,
  17. }
  18. c.Cache = accesstoken.New(c.load)
  19. return c
  20. }
  21. func (c *Cache) load(key accesstoken.CacheKey) (cortypes.UserAccessToken, error) {
  22. token, err := c.db.UserAccessToken().GetByID(c.db.DefCtx(), key.UserID, key.TokenID)
  23. if err == gorm.ErrRecordNotFound {
  24. return cortypes.UserAccessToken{}, accesstoken.ErrTokenNotFound
  25. }
  26. if err != nil {
  27. return cortypes.UserAccessToken{}, err
  28. }
  29. return token, nil
  30. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。