2026-06-03 18:19:50 +08:00

59 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package integration 定义 room-service 到外部服务的接口边界。
package integration
import (
"context"
"google.golang.org/grpc"
activityv1 "hyapp.local/api/proto/activity/v1"
walletv1 "hyapp.local/api/proto/wallet/v1"
)
// grpcWalletClient 是 WalletClient 的 gRPC 实现。
type grpcWalletClient struct {
// client 是 protobuf 生成的 wallet-service client。
client walletv1.WalletServiceClient
}
// NewGRPCWalletClient 用 gRPC 连接创建 wallet-service 客户端。
func NewGRPCWalletClient(conn *grpc.ClientConn) WalletClient {
return &grpcWalletClient{
client: walletv1.NewWalletServiceClient(conn),
}
}
// DebitGift 直接转调 wallet-service gRPC 接口。
func (c *grpcWalletClient) DebitGift(ctx context.Context, req *walletv1.DebitGiftRequest) (*walletv1.DebitGiftResponse, error) {
// 这里不吞错,账务失败必须原样阻断 SendGift 房间状态变更。
return c.client.DebitGift(ctx, req)
}
// BatchDebitGift 直接转调 wallet-service 批量送礼接口。
func (c *grpcWalletClient) BatchDebitGift(ctx context.Context, req *walletv1.BatchDebitGiftRequest) (*walletv1.BatchDebitGiftResponse, error) {
// 多目标送礼必须由 wallet-service 单事务结算room-service 不能自己循环单目标扣费。
return c.client.BatchDebitGift(ctx, req)
}
// GrantResourceGroup 直接转调 wallet-service 资源组发放接口。
func (c *grpcWalletClient) GrantResourceGroup(ctx context.Context, req *walletv1.GrantResourceGroupRequest) (*walletv1.ResourceGrantResponse, error) {
// 宝箱奖励以 resource group 为后台配置单位wallet-service 负责展开资产和权益。
return c.client.GrantResourceGroup(ctx, req)
}
type grpcLuckyGiftClient struct {
client activityv1.LuckyGiftServiceClient
}
// NewGRPCLuckyGiftClient 用 gRPC 连接创建 activity-service 幸运礼物客户端。
func NewGRPCLuckyGiftClient(conn *grpc.ClientConn) LuckyGiftClient {
return &grpcLuckyGiftClient{client: activityv1.NewLuckyGiftServiceClient(conn)}
}
func (c *grpcLuckyGiftClient) CheckLuckyGift(ctx context.Context, req *activityv1.CheckLuckyGiftRequest) (*activityv1.CheckLuckyGiftResponse, error) {
return c.client.CheckLuckyGift(ctx, req)
}
func (c *grpcLuckyGiftClient) ExecuteLuckyGiftDraw(ctx context.Context, req *activityv1.ExecuteLuckyGiftDrawRequest) (*activityv1.ExecuteLuckyGiftDrawResponse, error) {
return c.client.ExecuteLuckyGiftDraw(ctx, req)
}