This commit is contained in:
wangchuxiao 2023-06-02 20:52:16 +08:00
parent 0ab9294fab
commit 97aa17af6c
7 changed files with 63 additions and 36 deletions

View File

@ -5,20 +5,18 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/auth"
"github.com/gin-gonic/gin"
"google.golang.org/grpc"
)
func NewAuth(c discoveryregistry.SvcDiscoveryRegistry) *Auth {
conn, err := c.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAuthName)
func NewAuth(discov discoveryregistry.SvcDiscoveryRegistry) *Auth {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAuthName)
if err != nil {
panic(err)
// panic(err)
}
log.ZInfo(context.Background(), "auth rpc conn", "conn", conn)
return &Auth{conn: conn, discov: c}
return &Auth{conn: conn, discov: discov}
}
type Auth struct {

View File

@ -11,20 +11,25 @@ import (
"google.golang.org/grpc"
)
func NewConversation(c discoveryregistry.SvcDiscoveryRegistry) *Conversation {
conn, err := c.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImConversationName)
func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry) *Conversation {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImConversationName)
if err != nil {
panic(err)
// panic(err)
}
return &Conversation{conn: conn}
return &Conversation{conn: conn, discov: discov}
}
type Conversation struct {
conn *grpc.ClientConn
conn *grpc.ClientConn
discov discoveryregistry.SvcDiscoveryRegistry
}
func (o *Conversation) client(ctx context.Context) (conversation.ConversationClient, error) {
return conversation.NewConversationClient(o.conn), nil
c, err := o.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImConversationName)
if err != nil {
return nil, err
}
return conversation.NewConversationClient(c), nil
}
func (o *Conversation) GetAllConversations(c *gin.Context) {

View File

@ -12,20 +12,25 @@ import (
"github.com/gin-gonic/gin"
)
func NewFriend(c discoveryregistry.SvcDiscoveryRegistry) *Friend {
conn, err := c.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName)
func NewFriend(discov discoveryregistry.SvcDiscoveryRegistry) *Friend {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName)
if err != nil {
panic(err)
// panic(err)
}
return &Friend{conn: conn}
return &Friend{conn: conn, discov: discov}
}
type Friend struct {
conn *grpc.ClientConn
conn *grpc.ClientConn
discov discoveryregistry.SvcDiscoveryRegistry
}
func (o *Friend) client(ctx context.Context) (friend.FriendClient, error) {
return friend.NewFriendClient(o.conn), nil
c, err := o.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImFriendName)
if err != nil {
return nil, err
}
return friend.NewFriendClient(c), nil
}
func (o *Friend) ApplyToAddFriend(c *gin.Context) {

View File

@ -12,20 +12,25 @@ import (
"github.com/gin-gonic/gin"
)
func NewGroup(c discoveryregistry.SvcDiscoveryRegistry) *Group {
conn, err := c.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImGroupName)
func NewGroup(discov discoveryregistry.SvcDiscoveryRegistry) *Group {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImGroupName)
if err != nil {
panic(err)
// panic(err)
}
return &Group{conn: conn}
return &Group{conn: conn, discov: discov}
}
type Group struct {
conn *grpc.ClientConn
conn *grpc.ClientConn
discov discoveryregistry.SvcDiscoveryRegistry
}
func (o *Group) client(ctx context.Context) (group.GroupClient, error) {
return group.NewGroupClient(o.conn), nil
c, err := o.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImGroupName)
if err != nil {
return nil, err
}
return group.NewGroupClient(c), nil
}
func (o *Group) NewCreateGroup(c *gin.Context) {

View File

@ -21,17 +21,18 @@ import (
"google.golang.org/protobuf/proto"
)
func NewMsg(c discoveryregistry.SvcDiscoveryRegistry) *Message {
conn, err := c.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName)
func NewMsg(discov discoveryregistry.SvcDiscoveryRegistry) *Message {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName)
if err != nil {
panic(err)
// panic(err)
}
return &Message{conn: conn, validate: validator.New()}
return &Message{conn: conn, validate: validator.New(), discov: discov}
}
type Message struct {
conn *grpc.ClientConn
validate *validator.Validate
discov discoveryregistry.SvcDiscoveryRegistry
}
func (Message) SetOptions(options map[string]bool, value bool) {
@ -109,7 +110,11 @@ func (m Message) newUserSendMsgReq(c *gin.Context, params *apistruct.ManagementS
}
func (m *Message) client(ctx context.Context) (msg.MsgClient, error) {
return msg.NewMsgClient(m.conn), nil
c, err := m.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImMsgName)
if err != nil {
return nil, err
}
return msg.NewMsgClient(c), nil
}
func (m *Message) GetSeq(c *gin.Context) {

View File

@ -22,15 +22,20 @@ func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third {
if err != nil {
panic(err)
}
return &Third{conn: conn}
return &Third{conn: conn, discov: discov}
}
type Third struct {
conn *grpc.ClientConn
conn *grpc.ClientConn
discov discoveryregistry.SvcDiscoveryRegistry
}
func (o *Third) client(ctx context.Context) (third.ThirdClient, error) {
return third.NewThirdClient(o.conn), nil
conn, err := o.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImThirdName)
if err != nil {
return nil, err
}
return third.NewThirdClient(conn), nil
}
func (o *Third) ApplyPut(c *gin.Context) {

View File

@ -23,16 +23,20 @@ func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
panic(err)
}
log.ZInfo(context.Background(), "user rpc conn", "conn", conn)
return &User{conn: conn}
return &User{conn: conn, discov: discov}
}
type User struct {
conn *grpc.ClientConn
discov discoveryregistry.SvcDiscoveryRegistry
conn *grpc.ClientConn
}
func (u *User) client(ctx context.Context) (user.UserClient, error) {
return user.NewUserClient(u.conn), nil
conn, err := u.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImUserName)
if err != nil {
panic(err)
}
return user.NewUserClient(conn), nil
}
func (u *User) UserRegister(c *gin.Context) {