mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
grpcconn
This commit is contained in:
parent
0ab9294fab
commit
97aa17af6c
@ -5,20 +5,18 @@ import (
|
|||||||
|
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
|
"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/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/discoveryregistry"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/auth"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/auth"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewAuth(c discoveryregistry.SvcDiscoveryRegistry) *Auth {
|
func NewAuth(discov discoveryregistry.SvcDiscoveryRegistry) *Auth {
|
||||||
conn, err := c.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAuthName)
|
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAuthName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
// panic(err)
|
||||||
}
|
}
|
||||||
log.ZInfo(context.Background(), "auth rpc conn", "conn", conn)
|
return &Auth{conn: conn, discov: discov}
|
||||||
return &Auth{conn: conn, discov: c}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Auth struct {
|
type Auth struct {
|
||||||
|
@ -11,20 +11,25 @@ import (
|
|||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewConversation(c discoveryregistry.SvcDiscoveryRegistry) *Conversation {
|
func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry) *Conversation {
|
||||||
conn, err := c.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImConversationName)
|
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImConversationName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
// panic(err)
|
||||||
}
|
}
|
||||||
return &Conversation{conn: conn}
|
return &Conversation{conn: conn, discov: discov}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Conversation struct {
|
type Conversation struct {
|
||||||
conn *grpc.ClientConn
|
conn *grpc.ClientConn
|
||||||
|
discov discoveryregistry.SvcDiscoveryRegistry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Conversation) client(ctx context.Context) (conversation.ConversationClient, error) {
|
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) {
|
func (o *Conversation) GetAllConversations(c *gin.Context) {
|
||||||
|
@ -12,20 +12,25 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewFriend(c discoveryregistry.SvcDiscoveryRegistry) *Friend {
|
func NewFriend(discov discoveryregistry.SvcDiscoveryRegistry) *Friend {
|
||||||
conn, err := c.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName)
|
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
// panic(err)
|
||||||
}
|
}
|
||||||
return &Friend{conn: conn}
|
return &Friend{conn: conn, discov: discov}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Friend struct {
|
type Friend struct {
|
||||||
conn *grpc.ClientConn
|
conn *grpc.ClientConn
|
||||||
|
discov discoveryregistry.SvcDiscoveryRegistry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Friend) client(ctx context.Context) (friend.FriendClient, error) {
|
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) {
|
func (o *Friend) ApplyToAddFriend(c *gin.Context) {
|
||||||
|
@ -12,20 +12,25 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewGroup(c discoveryregistry.SvcDiscoveryRegistry) *Group {
|
func NewGroup(discov discoveryregistry.SvcDiscoveryRegistry) *Group {
|
||||||
conn, err := c.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImGroupName)
|
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImGroupName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
// panic(err)
|
||||||
}
|
}
|
||||||
return &Group{conn: conn}
|
return &Group{conn: conn, discov: discov}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Group struct {
|
type Group struct {
|
||||||
conn *grpc.ClientConn
|
conn *grpc.ClientConn
|
||||||
|
discov discoveryregistry.SvcDiscoveryRegistry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Group) client(ctx context.Context) (group.GroupClient, error) {
|
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) {
|
func (o *Group) NewCreateGroup(c *gin.Context) {
|
||||||
|
@ -21,17 +21,18 @@ import (
|
|||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewMsg(c discoveryregistry.SvcDiscoveryRegistry) *Message {
|
func NewMsg(discov discoveryregistry.SvcDiscoveryRegistry) *Message {
|
||||||
conn, err := c.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName)
|
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName)
|
||||||
if err != nil {
|
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 {
|
type Message struct {
|
||||||
conn *grpc.ClientConn
|
conn *grpc.ClientConn
|
||||||
validate *validator.Validate
|
validate *validator.Validate
|
||||||
|
discov discoveryregistry.SvcDiscoveryRegistry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Message) SetOptions(options map[string]bool, value bool) {
|
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) {
|
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) {
|
func (m *Message) GetSeq(c *gin.Context) {
|
||||||
|
@ -22,15 +22,20 @@ func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return &Third{conn: conn}
|
return &Third{conn: conn, discov: discov}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Third struct {
|
type Third struct {
|
||||||
conn *grpc.ClientConn
|
conn *grpc.ClientConn
|
||||||
|
discov discoveryregistry.SvcDiscoveryRegistry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Third) client(ctx context.Context) (third.ThirdClient, error) {
|
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) {
|
func (o *Third) ApplyPut(c *gin.Context) {
|
||||||
|
@ -23,16 +23,20 @@ func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
log.ZInfo(context.Background(), "user rpc conn", "conn", conn)
|
log.ZInfo(context.Background(), "user rpc conn", "conn", conn)
|
||||||
|
return &User{conn: conn, discov: discov}
|
||||||
return &User{conn: conn}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
conn *grpc.ClientConn
|
discov discoveryregistry.SvcDiscoveryRegistry
|
||||||
|
conn *grpc.ClientConn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) client(ctx context.Context) (user.UserClient, error) {
|
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) {
|
func (u *User) UserRegister(c *gin.Context) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user