Skip to content

Commit

Permalink
feat: im admin token cache
Browse files Browse the repository at this point in the history
  • Loading branch information
withchao committed Oct 25, 2023
1 parent 470bd04 commit 5b7f104
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/common/apicall/caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package apicall

import (
"context"
"github.com/OpenIMSDK/tools/log"
"sync"
"time"

Expand Down Expand Up @@ -66,10 +67,13 @@ func (c *Caller) ImAdminTokenWithDefaultAdmin(ctx context.Context) (string, erro
c.lock.Lock()
defer c.lock.Unlock()
if c.token == "" || c.timeout.Before(time.Now()) {
userID := config.GetDefaultIMAdmin()
token, err := c.UserToken(ctx, config.GetDefaultIMAdmin(), constant.AdminPlatformID)
if err != nil {
log.ZError(ctx, "get im admin token", err, "userID", userID)
return "", err
}
log.ZDebug(ctx, "get im admin token", "userID", userID)
c.token = token
c.timeout = time.Now().Add(time.Minute * 5)
}
Expand Down

0 comments on commit 5b7f104

Please sign in to comment.