4
4
"context"
5
5
"fmt"
6
6
"github.com/openimsdk/open-im-server/v3/pkg/rpcli"
7
+ pbAuth "github.com/openimsdk/protocol/auth"
7
8
"github.com/openimsdk/protocol/conversation"
8
9
"github.com/openimsdk/protocol/group"
9
10
"github.com/openimsdk/protocol/msg"
@@ -23,12 +24,8 @@ import (
23
24
"google.golang.org/grpc"
24
25
"google.golang.org/grpc/credentials/insecure"
25
26
26
- "net/http"
27
- "strings"
28
-
29
27
"github.com/openimsdk/open-im-server/v3/pkg/common/prommetrics"
30
28
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
31
- "github.com/openimsdk/open-im-server/v3/pkg/rpcclient"
32
29
"github.com/openimsdk/protocol/constant"
33
30
"github.com/openimsdk/tools/apiresp"
34
31
"github.com/openimsdk/tools/discovery"
@@ -61,31 +58,31 @@ func prommetricsGin() gin.HandlerFunc {
61
58
func newGinRouter (ctx context.Context , client discovery.SvcDiscoveryRegistry , config * Config ) (* gin.Engine , error ) {
62
59
client .AddOption (mw .GrpcClient (), grpc .WithTransportCredentials (insecure .NewCredentials ()),
63
60
grpc .WithDefaultServiceConfig (fmt .Sprintf (`{"LoadBalancingPolicy": "%s"}` , "round_robin" )))
64
- authConn , err := client .GetConn (ctx , config .Discovery . RpcService .Auth )
61
+ authConn , err := client .GetConn (ctx , config .Share . RpcRegisterName .Auth )
65
62
if err != nil {
66
63
return nil , err
67
64
}
68
- userConn , err := client .GetConn (ctx , config .Discovery . RpcService .User )
65
+ userConn , err := client .GetConn (ctx , config .Share . RpcRegisterName .User )
69
66
if err != nil {
70
67
return nil , err
71
68
}
72
- groupConn , err := client .GetConn (ctx , config .Discovery . RpcService .Group )
69
+ groupConn , err := client .GetConn (ctx , config .Share . RpcRegisterName .Group )
73
70
if err != nil {
74
71
return nil , err
75
72
}
76
- friendConn , err := client .GetConn (ctx , config .Discovery . RpcService .Friend )
73
+ friendConn , err := client .GetConn (ctx , config .Share . RpcRegisterName .Friend )
77
74
if err != nil {
78
75
return nil , err
79
76
}
80
- conversationConn , err := client .GetConn (ctx , config .Discovery . RpcService .Conversation )
77
+ conversationConn , err := client .GetConn (ctx , config .Share . RpcRegisterName .Conversation )
81
78
if err != nil {
82
79
return nil , err
83
80
}
84
- thirdConn , err := client .GetConn (ctx , config .Discovery . RpcService .Third )
81
+ thirdConn , err := client .GetConn (ctx , config .Share . RpcRegisterName .Third )
85
82
if err != nil {
86
83
return nil , err
87
84
}
88
- msgConn , err := client .GetConn (ctx , config .Discovery . RpcService .Msg )
85
+ msgConn , err := client .GetConn (ctx , config .Share . RpcRegisterName .Msg )
89
86
if err != nil {
90
87
return nil , err
91
88
}
@@ -94,15 +91,6 @@ func newGinRouter(ctx context.Context, client discovery.SvcDiscoveryRegistry, co
94
91
if v , ok := binding .Validator .Engine ().(* validator.Validate ); ok {
95
92
_ = v .RegisterValidation ("required_if" , RequiredIf )
96
93
}
97
- // init rpc client here
98
- userRpc := rpcclient .NewUser (disCov , config .Share .RpcRegisterName .User , config .Share .RpcRegisterName .MessageGateway ,
99
- config .Share .IMAdminUserID )
100
- groupRpc := rpcclient .NewGroup (disCov , config .Share .RpcRegisterName .Group )
101
- friendRpc := rpcclient .NewFriend (disCov , config .Share .RpcRegisterName .Friend )
102
- messageRpc := rpcclient .NewMessage (disCov , config .Share .RpcRegisterName .Msg )
103
- conversationRpc := rpcclient .NewConversation (disCov , config .Share .RpcRegisterName .Conversation )
104
- authRpc := rpcclient .NewAuth (disCov , config .Share .RpcRegisterName .Auth )
105
- thirdRpc := rpcclient .NewThird (disCov , config .Share .RpcRegisterName .Third , config .API .Prometheus .GrafanaURL )
106
94
switch config .API .Api .CompressionLevel {
107
95
case NoCompression :
108
96
case DefaultCompression :
@@ -112,10 +100,10 @@ func newGinRouter(ctx context.Context, client discovery.SvcDiscoveryRegistry, co
112
100
case BestSpeed :
113
101
r .Use (gzip .Gzip (gzip .BestSpeed ))
114
102
}
115
- r .Use (prommetricsGin (), gin .RecoveryWithWriter (gin .DefaultErrorWriter , mw .GinPanicErr ), mw .CorsHandler (), mw . GinParseOperationID (), GinParseToken ( rpcli . NewAuthClient ( authConn )))
116
- j := jssdk . NewJSSdkApi ( )
103
+ r .Use (prommetricsGin (), gin .RecoveryWithWriter (gin .DefaultErrorWriter , mw .GinPanicErr ), mw .CorsHandler (),
104
+ mw . GinParseOperationID (), GinParseToken ( rpcli . NewAuthClient ( authConn )) )
117
105
118
- u := NewUserApi (user .NewUserClient (userConn ), client , config .Discovery . RpcService )
106
+ u := NewUserApi (user .NewUserClient (userConn ), client , config .Share . RpcRegisterName )
119
107
{
120
108
userRouterGroup := r .Group ("/user" )
121
109
userRouterGroup .POST ("/user_register" , u .UserRegister )
@@ -290,25 +278,12 @@ func newGinRouter(ctx context.Context, client discovery.SvcDiscoveryRegistry, co
290
278
}
291
279
292
280
{
281
+ j := jssdk .NewJSSdkApi (rpcli .NewUserClient (userConn ), rpcli .NewRelationClient (friendConn ),
282
+ rpcli .NewGroupClient (groupConn ), rpcli .NewConversationClient (conversationConn ), rpcli .NewMsgClient (msgConn ))
293
283
jssdk := r .Group ("/jssdk" )
294
284
jssdk .POST ("/get_conversations" , j .GetConversations )
295
285
jssdk .POST ("/get_active_conversations" , j .GetActiveConversations )
296
286
}
297
- {
298
- pd := NewPrometheusDiscoveryApi (config , client )
299
- proDiscoveryGroup := r .Group ("/prometheus_discovery" , pd .Enable )
300
- proDiscoveryGroup .GET ("/api" , pd .Api )
301
- proDiscoveryGroup .GET ("/user" , pd .User )
302
- proDiscoveryGroup .GET ("/group" , pd .Group )
303
- proDiscoveryGroup .GET ("/msg" , pd .Msg )
304
- proDiscoveryGroup .GET ("/friend" , pd .Friend )
305
- proDiscoveryGroup .GET ("/conversation" , pd .Conversation )
306
- proDiscoveryGroup .GET ("/third" , pd .Third )
307
- proDiscoveryGroup .GET ("/auth" , pd .Auth )
308
- proDiscoveryGroup .GET ("/push" , pd .Push )
309
- proDiscoveryGroup .GET ("/msg_gateway" , pd .MessageGateway )
310
- proDiscoveryGroup .GET ("/msg_transfer" , pd .MessageTransfer )
311
- }
312
287
313
288
return r , nil
314
289
}
0 commit comments