|
1234567891011121314151617181920212223242526272829303132333435363738 |
- package accesstoken
-
- import (
- "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/accesstoken"
- "gitlink.org.cn/cloudream/jcs-pub/coordinator/internal/db"
- cortypes "gitlink.org.cn/cloudream/jcs-pub/coordinator/types"
- "gorm.io/gorm"
- )
-
- type ExitEvent = accesstoken.ExitEvent
-
- type CacheKey = accesstoken.CacheKey
-
- type Cache struct {
- *accesstoken.Cache
- db *db.DB
- }
-
- func New(db *db.DB) *Cache {
- c := &Cache{
- db: db,
- }
- c.Cache = accesstoken.New(c.load)
-
- return c
- }
-
- func (c *Cache) load(key accesstoken.CacheKey) (cortypes.UserAccessToken, error) {
- token, err := c.db.UserAccessToken().GetByID(c.db.DefCtx(), key.UserID, key.TokenID)
- if err == gorm.ErrRecordNotFound {
- return cortypes.UserAccessToken{}, accesstoken.ErrTokenNotFound
- }
- if err != nil {
- return cortypes.UserAccessToken{}, err
- }
-
- return token, nil
- }
|