mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
grpc conn
This commit is contained in:
parent
232abf46a4
commit
290d7cffde
@ -8,22 +8,23 @@ import (
|
||||
"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 {
|
||||
return &Auth{c: c}
|
||||
conn, err := c.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAuthName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &Auth{conn: conn}
|
||||
}
|
||||
|
||||
type Auth struct {
|
||||
c discoveryregistry.SvcDiscoveryRegistry
|
||||
conn *grpc.ClientConn
|
||||
}
|
||||
|
||||
func (o *Auth) client(ctx context.Context) (auth.AuthClient, error) {
|
||||
conn, err := o.c.GetConn(ctx, config.Config.RpcRegisterName.OpenImAuthName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auth.NewAuthClient(conn), nil
|
||||
return auth.NewAuthClient(o.conn), nil
|
||||
}
|
||||
|
||||
func (o *Auth) UserRegister(c *gin.Context) {
|
||||
|
@ -6,23 +6,24 @@ import (
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/friend"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type BlackClient struct {
|
||||
*MetaClient
|
||||
conn *grpc.ClientConn
|
||||
}
|
||||
|
||||
func NewBlackClient(zk discoveryRegistry.SvcDiscoveryRegistry) *BlackClient {
|
||||
return &BlackClient{NewMetaClient(zk, config.Config.RpcRegisterName.OpenImFriendName)}
|
||||
func NewBlackClient(discov discoveryRegistry.SvcDiscoveryRegistry) *BlackClient {
|
||||
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &BlackClient{conn: conn}
|
||||
}
|
||||
|
||||
// possibleBlackUserID是否被userID拉黑,也就是是否在userID的黑名单中
|
||||
func (b *BlackClient) IsBlocked(ctx context.Context, possibleBlackUserID, userID string) (bool, error) {
|
||||
cc, err := b.getConn(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
r, err := friend.NewFriendClient(cc).IsBlack(ctx, &friend.IsBlackReq{UserID1: possibleBlackUserID, UserID2: userID})
|
||||
r, err := friend.NewFriendClient(b.conn).IsBlack(ctx, &friend.IsBlackReq{UserID1: possibleBlackUserID, UserID2: userID})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user