mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-28 04:48:44 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
This commit is contained in:
commit
ccccf35344
@ -2,6 +2,7 @@ package getui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ type Resp struct {
|
|||||||
func (r *Resp) parseError() (err error) {
|
func (r *Resp) parseError() (err error) {
|
||||||
switch r.Code {
|
switch r.Code {
|
||||||
case tokenExpireCode:
|
case tokenExpireCode:
|
||||||
err = TokenExpireError
|
err = ErrTokenExpire
|
||||||
case 0:
|
case 0:
|
||||||
err = nil
|
err = nil
|
||||||
default:
|
default:
|
||||||
|
@ -1,28 +1,31 @@
|
|||||||
package getui
|
package getui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush"
|
"github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
|
||||||
http2 "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http"
|
http2 "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
|
||||||
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils/splitter"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils/splitter"
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
TokenExpireError = errors.New("token expire")
|
ErrTokenExpire = errors.New("token expire")
|
||||||
UserIDEmptyError = errors.New("userIDs is empty")
|
ErrUserIDEmpty = errors.New("userIDs is empty")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -50,7 +53,8 @@ func NewClient(cache cache.MsgModel) *Client {
|
|||||||
func (g *Client) Push(ctx context.Context, userIDs []string, title, content string, opts *offlinepush.Opts) error {
|
func (g *Client) Push(ctx context.Context, userIDs []string, title, content string, opts *offlinepush.Opts) error {
|
||||||
token, err := g.cache.GetGetuiToken(ctx)
|
token, err := g.cache.GetGetuiToken(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == redis.Nil {
|
if errs.Unwrap(err) == redis.Nil {
|
||||||
|
log.ZInfo(ctx, "getui token not exist in redis")
|
||||||
token, err = g.getTokenAndSave2Redis(ctx)
|
token, err = g.getTokenAndSave2Redis(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -83,10 +87,10 @@ func (g *Client) Push(ctx context.Context, userIDs []string, title, content stri
|
|||||||
} else if len(userIDs) == 1 {
|
} else if len(userIDs) == 1 {
|
||||||
err = g.singlePush(ctx, token, userIDs[0], pushReq)
|
err = g.singlePush(ctx, token, userIDs[0], pushReq)
|
||||||
} else {
|
} else {
|
||||||
return UserIDEmptyError
|
return ErrUserIDEmpty
|
||||||
}
|
}
|
||||||
switch err {
|
switch err {
|
||||||
case TokenExpireError:
|
case ErrTokenExpire:
|
||||||
token, err = g.getTokenAndSave2Redis(ctx)
|
token, err = g.getTokenAndSave2Redis(ctx)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user