mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-02 08:05:58 +08:00
Error code standardization
This commit is contained in:
@@ -1,9 +1,34 @@
|
||||
package controller
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"Open_IM/pkg/common/db/cache"
|
||||
"context"
|
||||
"github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
type AuthInterface interface {
|
||||
GetTokens(ctx context.Context, userID, platform string) (map[string]int, error)
|
||||
DeleteToken(ctx context.Context, userID, platform string) error
|
||||
CreateToken(ctx context.Context, userID string, platformID int, ttl int64) (string, error)
|
||||
//结果为空 不返回错误
|
||||
GetTokensWithoutError(ctx context.Context, userID, platform string) (map[string]int, error)
|
||||
|
||||
//创建token
|
||||
CreateToken(ctx context.Context, userID string, platform string) (string, error)
|
||||
}
|
||||
|
||||
type AuthController struct {
|
||||
database *cache.TokenRedis
|
||||
}
|
||||
|
||||
func NewAuthController(rdb redis.UniversalClient, accessSecret string, accessExpire int64) *AuthController {
|
||||
cache.NewRedisClient(rdb)
|
||||
return &AuthController{database: cache.NewTokenRedis(cache.NewRedisClient(rdb), accessSecret, accessExpire)}
|
||||
}
|
||||
|
||||
// 结果为空 不返回错误
|
||||
func (a *AuthController) GetTokensWithoutError(ctx context.Context, userID, platform string) (map[string]int, error) {
|
||||
return a.database.GetTokensWithoutError(ctx, userID, platform)
|
||||
}
|
||||
|
||||
// 创建token
|
||||
func (a *AuthController) CreateToken(ctx context.Context, userID string, platform string) (string, error) {
|
||||
return a.database.CreateToken(ctx, userID, platform)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user