Skip to content

Commit ab32167

Browse files
authored
Merge pull request #3359 from withchao/pre-release-v3.8.4
fix: standalone mode cannot be used
2 parents 3526672 + 9616e92 commit ab32167

File tree

10 files changed

+126
-106
lines changed

10 files changed

+126
-106
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
1414
github.com/mitchellh/mapstructure v1.5.0
1515
github.com/openimsdk/protocol v0.0.73-alpha.6
16-
github.com/openimsdk/tools v0.0.50-alpha.81
16+
github.com/openimsdk/tools v0.0.50-alpha.83
1717
github.com/pkg/errors v0.9.1 // indirect
1818
github.com/prometheus/client_golang v1.18.0
1919
github.com/stretchr/testify v1.9.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ github.com/openimsdk/gomake v0.0.15-alpha.5 h1:eEZCEHm+NsmcO3onXZPIUbGFCYPYbsX5b
349349
github.com/openimsdk/gomake v0.0.15-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
350350
github.com/openimsdk/protocol v0.0.73-alpha.6 h1:sna9coWG7HN1zObBPtvG0Ki/vzqHXiB4qKbA5P3w7kc=
351351
github.com/openimsdk/protocol v0.0.73-alpha.6/go.mod h1:WF7EuE55vQvpyUAzDXcqg+B+446xQyEba0X35lTINmw=
352-
github.com/openimsdk/tools v0.0.50-alpha.81 h1:VbuJKtigNXLkCKB/Q6f2UHsqoSaTOAwS8F51c1nhOCA=
353-
github.com/openimsdk/tools v0.0.50-alpha.81/go.mod h1:n2poR3asX1e1XZce4O+MOWAp+X02QJRFvhcLCXZdzRo=
352+
github.com/openimsdk/tools v0.0.50-alpha.83 h1:7c1D40YGqIWUmGfCII5pduETGC/8c2DyS9SQ4LvoplU=
353+
github.com/openimsdk/tools v0.0.50-alpha.83/go.mod h1:n2poR3asX1e1XZce4O+MOWAp+X02QJRFvhcLCXZdzRo=
354354
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
355355
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
356356
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=

internal/api/router.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ import (
99
"github.com/gin-gonic/gin"
1010
"github.com/gin-gonic/gin/binding"
1111
"github.com/go-playground/validator/v10"
12-
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
13-
"github.com/openimsdk/tools/mcontext"
14-
"github.com/openimsdk/tools/utils/datautil"
15-
1612
"github.com/openimsdk/open-im-server/v3/internal/api/jssdk"
13+
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
1714
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
1815
"github.com/openimsdk/open-im-server/v3/pkg/common/prommetrics"
1916
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
@@ -357,9 +354,7 @@ func GinParseToken(authClient *rpcli.AuthClient) gin.HandlerFunc {
357354

358355
func setGinIsAdmin(imAdminUserID []string) gin.HandlerFunc {
359356
return func(c *gin.Context) {
360-
opUserID := mcontext.GetOpUserID(c)
361-
admin := datautil.Contain(opUserID, imAdminUserID...)
362-
c.Set(authverify.CtxIsAdminKey, admin)
357+
c.Set(authverify.CtxAdminUserIDsKey, imAdminUserID)
363358
}
364359
}
365360

internal/msggateway/ws_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type WsServer struct {
4949
unregisterChan chan *Client
5050
kickHandlerChan chan *kickHandler
5151
clients UserMap
52-
online *rpccache.OnlineCache
52+
online rpccache.OnlineCache
5353
subscription *Subscription
5454
clientPool sync.Pool
5555
onlineUserNum atomic.Int64

internal/msgtransfer/online_msg_to_mongo_handler.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,7 @@ func (mc *OnlineHistoryMongoConsumerHandler) HandleChatWs2Mongo(ctx context.Cont
4848
log.ZDebug(ctx, "mongo consumer recv msg", "msgs", msgFromMQ.String())
4949
err = mc.msgTransferDatabase.BatchInsertChat2DB(ctx, msgFromMQ.ConversationID, msgFromMQ.MsgData, msgFromMQ.LastSeq)
5050
if err != nil {
51-
log.ZError(
52-
ctx,
53-
"single data insert to mongo err",
54-
err,
55-
"msg",
56-
msgFromMQ.MsgData,
57-
"conversationID",
58-
msgFromMQ.ConversationID,
59-
)
51+
log.ZError(ctx, "single data insert to mongo err", err, "msg", msgFromMQ.MsgData, "conversationID", msgFromMQ.ConversationID)
6052
prommetrics.MsgInsertMongoFailedCounter.Inc()
6153
} else {
6254
prommetrics.MsgInsertMongoSuccessCounter.Inc()

internal/push/push_handler.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type ConsumerHandler struct {
3333
offlinePusher offlinepush.OfflinePusher
3434
onlinePusher OnlinePusher
3535
pushDatabase controller.PushDatabase
36-
onlineCache *rpccache.OnlineCache
36+
onlineCache rpccache.OnlineCache
3737
groupLocalCache *rpccache.GroupLocalCache
3838
conversationLocalCache *rpccache.ConversationLocalCache
3939
webhookClient *webhook.Client
@@ -120,11 +120,7 @@ func (c *ConsumerHandler) HandleMs2PsChat(ctx context.Context, msg []byte) {
120120
}
121121

122122
func (c *ConsumerHandler) WaitCache() {
123-
c.onlineCache.Lock.Lock()
124-
for c.onlineCache.CurrentPhase.Load() < rpccache.DoSubscribeOver {
125-
c.onlineCache.Cond.Wait()
126-
}
127-
c.onlineCache.Lock.Unlock()
123+
c.onlineCache.WaitCache()
128124
}
129125

130126
// Push2User Suitable for two types of conversations, one is SingleChatType and the other is NotificationChatType.

pkg/authverify/token.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ func CheckSystemAccount(ctx context.Context, level int32) bool {
5151
}
5252

5353
const (
54-
CtxIsAdminKey = "CtxIsAdminKey"
54+
CtxAdminUserIDsKey = "CtxAdminUserIDsKey"
5555
)
5656

5757
func WithIMAdminUserIDs(ctx context.Context, imAdminUserID []string) context.Context {
58-
return context.WithValue(ctx, CtxIsAdminKey, imAdminUserID)
58+
return context.WithValue(ctx, CtxAdminUserIDsKey, imAdminUserID)
5959
}
6060

6161
func GetIMAdminUserIDs(ctx context.Context) []string {
62-
imAdminUserID, _ := ctx.Value(CtxIsAdminKey).([]string)
62+
imAdminUserID, _ := ctx.Value(CtxAdminUserIDsKey).([]string)
6363
return imAdminUserID
6464
}
6565

pkg/common/startrpc/start.go

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -47,64 +47,6 @@ func init() {
4747
prommetrics.RegistryAll()
4848
}
4949

50-
func getConfigRpcMaxRequestBody(value reflect.Value) *conf.MaxRequestBody {
51-
for value.Kind() == reflect.Pointer {
52-
value = value.Elem()
53-
}
54-
if value.Kind() == reflect.Struct {
55-
num := value.NumField()
56-
for i := 0; i < num; i++ {
57-
field := value.Field(i)
58-
if !field.CanInterface() {
59-
continue
60-
}
61-
for field.Kind() == reflect.Pointer {
62-
field = field.Elem()
63-
}
64-
switch elem := field.Interface().(type) {
65-
case conf.Share:
66-
return &elem.RPCMaxBodySize
67-
case conf.MaxRequestBody:
68-
return &elem
69-
}
70-
if field.Kind() == reflect.Struct {
71-
if elem := getConfigRpcMaxRequestBody(field); elem != nil {
72-
return elem
73-
}
74-
}
75-
}
76-
}
77-
return nil
78-
}
79-
80-
func getConfigShare(value reflect.Value) *conf.Share {
81-
for value.Kind() == reflect.Pointer {
82-
value = value.Elem()
83-
}
84-
if value.Kind() == reflect.Struct {
85-
num := value.NumField()
86-
for i := 0; i < num; i++ {
87-
field := value.Field(i)
88-
if !field.CanInterface() {
89-
continue
90-
}
91-
for field.Kind() == reflect.Pointer {
92-
field = field.Elem()
93-
}
94-
switch elem := field.Interface().(type) {
95-
case conf.Share:
96-
return &elem
97-
}
98-
if field.Kind() == reflect.Struct {
99-
if elem := getConfigShare(field); elem != nil {
100-
return elem
101-
}
102-
}
103-
}
104-
}
105-
return nil
106-
}
107-
10850
func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *conf.Prometheus, listenIP,
10951
registerIP string, autoSetPorts bool, rpcPorts []int, index int, rpcRegisterName string, notification *conf.Notification, config T,
11052
watchConfigNames []string, watchServiceNames []string,
@@ -122,8 +64,8 @@ func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *c
12264

12365
options = append(options,
12466
grpcsrv.GrpcServerMetadataContext(),
125-
grpcsrv.GrpcServerLogger(),
12667
grpcsrv.GrpcServerErrorConvert(),
68+
grpcsrv.GrpcServerLogger(),
12769
grpcsrv.GrpcServerRequestValidate(),
12870
grpcsrv.GrpcServerPanicCapture(),
12971
)

pkg/common/startrpc/tools.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package startrpc
2+
3+
import (
4+
"reflect"
5+
6+
conf "github.com/openimsdk/open-im-server/v3/pkg/common/config"
7+
)
8+
9+
func getConfig[T any](value reflect.Value) *T {
10+
for value.Kind() == reflect.Pointer {
11+
value = value.Elem()
12+
}
13+
if value.Kind() == reflect.Struct {
14+
num := value.NumField()
15+
for i := 0; i < num; i++ {
16+
field := value.Field(i)
17+
for field.Kind() == reflect.Pointer {
18+
field = field.Elem()
19+
}
20+
if field.Kind() == reflect.Struct {
21+
if elem, ok := field.Interface().(T); ok {
22+
return &elem
23+
}
24+
if elem := getConfig[T](field); elem != nil {
25+
return elem
26+
}
27+
}
28+
}
29+
}
30+
return nil
31+
}
32+
33+
func getConfigRpcMaxRequestBody(value reflect.Value) *conf.MaxRequestBody {
34+
return getConfig[conf.MaxRequestBody](value)
35+
}
36+
37+
func getConfigShare(value reflect.Value) *conf.Share {
38+
return getConfig[conf.Share](value)
39+
}

0 commit comments

Comments
 (0)