31 lines
715 B
Go
31 lines
715 B
Go
package usergrpc
|
||
|
||
import (
|
||
"context"
|
||
"time"
|
||
|
||
gatewaypb "chatappgateway/api/proto"
|
||
)
|
||
|
||
// Client 封装用户服务 gRPC client,并统一超时控制。
|
||
type Client struct {
|
||
timeout time.Duration
|
||
client gatewaypb.ChatAppUserClient
|
||
}
|
||
|
||
// New 根据底层 gRPC client 构造用户服务调用器。
|
||
func New(client gatewaypb.ChatAppUserClient, timeout time.Duration) *Client {
|
||
return &Client{
|
||
timeout: timeout,
|
||
client: client,
|
||
}
|
||
}
|
||
|
||
// Login 调用用户服务登录接口。
|
||
func (c *Client) Login(ctx context.Context, request *gatewaypb.LoginRequest) (*gatewaypb.LoginResponse, error) {
|
||
callCtx, cancel := context.WithTimeout(ctx, c.timeout)
|
||
defer cancel()
|
||
|
||
return c.client.Login(callCtx, request)
|
||
}
|