parent
5e634ac91f
commit
ee8ee48418
@ -1,43 +1,27 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/auth"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewAuth(discov discoveryregistry.SvcDiscoveryRegistry) *Auth {
|
||||
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAuthName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := auth.NewAuthClient(conn)
|
||||
return &Auth{discov: discov, conn: conn, client: client}
|
||||
}
|
||||
|
||||
type Auth struct {
|
||||
conn *grpc.ClientConn
|
||||
client auth.AuthClient
|
||||
discov discoveryregistry.SvcDiscoveryRegistry
|
||||
}
|
||||
type AuthApi rpcclient.Auth
|
||||
|
||||
func (o *Auth) Client() auth.AuthClient {
|
||||
return o.client
|
||||
func NewAuthApi(discov discoveryregistry.SvcDiscoveryRegistry) AuthApi {
|
||||
return AuthApi(*rpcclient.NewAuth(discov))
|
||||
}
|
||||
|
||||
func (o *Auth) UserToken(c *gin.Context) {
|
||||
func (o *AuthApi) UserToken(c *gin.Context) {
|
||||
a2r.Call(auth.AuthClient.UserToken, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Auth) ParseToken(c *gin.Context) {
|
||||
func (o *AuthApi) ParseToken(c *gin.Context) {
|
||||
a2r.Call(auth.AuthClient.ParseToken, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Auth) ForceLogout(c *gin.Context) {
|
||||
func (o *AuthApi) ForceLogout(c *gin.Context) {
|
||||
a2r.Call(auth.AuthClient.ForceLogout, o.Client, c)
|
||||
}
|
||||
|
@ -1,65 +1,49 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry) *Conversation {
|
||||
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImConversationName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := conversation.NewConversationClient(conn)
|
||||
return &Conversation{discov: discov, conn: conn, client: client}
|
||||
}
|
||||
|
||||
type Conversation struct {
|
||||
client conversation.ConversationClient
|
||||
conn *grpc.ClientConn
|
||||
discov discoveryregistry.SvcDiscoveryRegistry
|
||||
}
|
||||
type ConversationApi rpcclient.Conversation
|
||||
|
||||
func (o *Conversation) Client() conversation.ConversationClient {
|
||||
return o.client
|
||||
func NewConversationApi(discov discoveryregistry.SvcDiscoveryRegistry) ConversationApi {
|
||||
return ConversationApi(*rpcclient.NewConversation(discov))
|
||||
}
|
||||
|
||||
func (o *Conversation) GetAllConversations(c *gin.Context) {
|
||||
func (o *ConversationApi) GetAllConversations(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.GetAllConversations, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Conversation) GetConversation(c *gin.Context) {
|
||||
func (o *ConversationApi) GetConversation(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.GetConversation, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Conversation) GetConversations(c *gin.Context) {
|
||||
func (o *ConversationApi) GetConversations(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.GetConversations, o.Client, c)
|
||||
}
|
||||
|
||||
// deprecated
|
||||
func (o *Conversation) SetConversation(c *gin.Context) {
|
||||
func (o *ConversationApi) SetConversation(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.SetConversation, o.Client, c)
|
||||
}
|
||||
|
||||
// deprecated
|
||||
func (o *Conversation) BatchSetConversations(c *gin.Context) {
|
||||
func (o *ConversationApi) BatchSetConversations(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.BatchSetConversations, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Conversation) SetRecvMsgOpt(c *gin.Context) {
|
||||
func (o *ConversationApi) SetRecvMsgOpt(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.SetRecvMsgOpt, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Conversation) ModifyConversationField(c *gin.Context) {
|
||||
func (o *ConversationApi) ModifyConversationField(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.ModifyConversationField, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Conversation) SetConversations(c *gin.Context) {
|
||||
func (o *ConversationApi) SetConversations(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.SetConversations, o.Client, c)
|
||||
}
|
||||
|
@ -1,80 +1,64 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/friend"
|
||||
"google.golang.org/grpc"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func NewFriend(discov discoveryregistry.SvcDiscoveryRegistry) *Friend {
|
||||
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := friend.NewFriendClient(conn)
|
||||
return &Friend{discov: discov, conn: conn, client: client}
|
||||
}
|
||||
|
||||
type Friend struct {
|
||||
conn *grpc.ClientConn
|
||||
client friend.FriendClient
|
||||
discov discoveryregistry.SvcDiscoveryRegistry
|
||||
}
|
||||
type FriendApi rpcclient.Friend
|
||||
|
||||
func (o *Friend) Client() friend.FriendClient {
|
||||
return friend.NewFriendClient(o.conn)
|
||||
func NewFriendApi(discov discoveryregistry.SvcDiscoveryRegistry) FriendApi {
|
||||
return FriendApi(*rpcclient.NewFriend(discov))
|
||||
}
|
||||
|
||||
func (o *Friend) ApplyToAddFriend(c *gin.Context) {
|
||||
func (o *FriendApi) ApplyToAddFriend(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.ApplyToAddFriend, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Friend) RespondFriendApply(c *gin.Context) {
|
||||
func (o *FriendApi) RespondFriendApply(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.RespondFriendApply, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Friend) DeleteFriend(c *gin.Context) {
|
||||
func (o *FriendApi) DeleteFriend(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.DeleteFriend, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Friend) GetFriendApplyList(c *gin.Context) {
|
||||
func (o *FriendApi) GetFriendApplyList(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.GetPaginationFriendsApplyTo, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Friend) GetSelfApplyList(c *gin.Context) {
|
||||
func (o *FriendApi) GetSelfApplyList(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.GetPaginationFriendsApplyFrom, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Friend) GetFriendList(c *gin.Context) {
|
||||
func (o *FriendApi) GetFriendList(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.GetPaginationFriends, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Friend) SetFriendRemark(c *gin.Context) {
|
||||
func (o *FriendApi) SetFriendRemark(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.SetFriendRemark, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Friend) AddBlack(c *gin.Context) {
|
||||
func (o *FriendApi) AddBlack(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.AddBlack, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Friend) GetPaginationBlacks(c *gin.Context) {
|
||||
func (o *FriendApi) GetPaginationBlacks(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.GetPaginationBlacks, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Friend) RemoveBlack(c *gin.Context) {
|
||||
func (o *FriendApi) RemoveBlack(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.RemoveBlack, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Friend) ImportFriends(c *gin.Context) {
|
||||
func (o *FriendApi) ImportFriends(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.ImportFriends, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Friend) IsFriend(c *gin.Context) {
|
||||
func (o *FriendApi) IsFriend(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.IsFriend, o.Client, c)
|
||||
}
|
||||
|
@ -1,35 +1,19 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/user"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewStatistics(discov discoveryregistry.SvcDiscoveryRegistry) *Statistics {
|
||||
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := user.NewUserClient(conn)
|
||||
return &Statistics{discov: discov, client: client, conn: conn}
|
||||
}
|
||||
|
||||
type Statistics struct {
|
||||
conn *grpc.ClientConn
|
||||
client user.UserClient
|
||||
discov discoveryregistry.SvcDiscoveryRegistry
|
||||
}
|
||||
type StatisticsApi rpcclient.User
|
||||
|
||||
func (s *Statistics) Client() user.UserClient {
|
||||
return s.client
|
||||
func NewStatisticsApi(discov discoveryregistry.SvcDiscoveryRegistry) StatisticsApi {
|
||||
return StatisticsApi(*rpcclient.NewUser(discov))
|
||||
}
|
||||
|
||||
func (s *Statistics) UserRegister(c *gin.Context) {
|
||||
func (s *StatisticsApi) UserRegister(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.UserRegisterCount, s.Client, c)
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package rpcclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/auth"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewAuth(discov discoveryregistry.SvcDiscoveryRegistry) *Auth {
|
||||
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAuthName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := auth.NewAuthClient(conn)
|
||||
return &Auth{discov: discov, conn: conn, Client: client}
|
||||
}
|
||||
|
||||
type Auth struct {
|
||||
conn *grpc.ClientConn
|
||||
Client auth.AuthClient
|
||||
discov discoveryregistry.SvcDiscoveryRegistry
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package rpcclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type MetaClient struct {
|
||||
// contains filtered or unexported fields
|
||||
client discoveryregistry.SvcDiscoveryRegistry
|
||||
rpcRegisterName string
|
||||
}
|
||||
|
||||
func NewMetaClient(client discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName string, opts ...MetaClientOptions) *MetaClient {
|
||||
c := &MetaClient{
|
||||
client: client,
|
||||
rpcRegisterName: rpcRegisterName,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(c)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
type MetaClientOptions func(*MetaClient)
|
||||
|
||||
func (m *MetaClient) getConn(ctx context.Context) (*grpc.ClientConn, error) {
|
||||
return m.client.GetConn(ctx, m.rpcRegisterName)
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package rpcclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type Third struct {
|
||||
conn *grpc.ClientConn
|
||||
Client third.ThirdClient
|
||||
discov discoveryregistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third {
|
||||
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImThirdName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := third.NewThirdClient(conn)
|
||||
return &Third{discov: discov, Client: client, conn: conn}
|
||||
}
|
Loading…
Reference in new issue