31 lines
755 B
Go
31 lines
755 B
Go
package usergrpc
|
||
|
||
import (
|
||
"context"
|
||
"time"
|
||
|
||
commonpb "gitea.haiyihy.com/hy/chatappcommon/proto"
|
||
)
|
||
|
||
// Client 封装用户服务 gRPC client,并统一超时控制。
|
||
type Client struct {
|
||
timeout time.Duration
|
||
client commonpb.ChatAppUserServiceClient
|
||
}
|
||
|
||
// New 根据底层 gRPC client 构造用户服务调用器。
|
||
func New(client commonpb.ChatAppUserServiceClient, timeout time.Duration) *Client {
|
||
return &Client{
|
||
timeout: timeout,
|
||
client: client,
|
||
}
|
||
}
|
||
|
||
// Register 调用用户服务注册接口。
|
||
func (c *Client) Register(ctx context.Context, request *commonpb.RegisterRequest) (*commonpb.RegisterResponse, error) {
|
||
callCtx, cancel := context.WithTimeout(ctx, c.timeout)
|
||
defer cancel()
|
||
|
||
return c.client.Register(callCtx, request)
|
||
}
|