2026-05-12 19:34:47 +08:00

40 lines
1.3 KiB
Go

package client
import (
"context"
"google.golang.org/grpc"
gamev1 "hyapp.local/api/proto/game/v1"
)
// GameClient 抽象 gateway 对 game-service App 与回调 RPC 的依赖。
type GameClient interface {
ListGames(ctx context.Context, req *gamev1.ListGamesRequest) (*gamev1.ListGamesResponse, error)
LaunchGame(ctx context.Context, req *gamev1.LaunchGameRequest) (*gamev1.LaunchGameResponse, error)
HandleCallback(ctx context.Context, req *gamev1.CallbackRequest) (*gamev1.CallbackResponse, error)
}
type grpcGameClient struct {
app gamev1.GameAppServiceClient
callback gamev1.GameCallbackServiceClient
}
func NewGRPCGameClient(conn *grpc.ClientConn) GameClient {
return &grpcGameClient{
app: gamev1.NewGameAppServiceClient(conn),
callback: gamev1.NewGameCallbackServiceClient(conn),
}
}
func (c *grpcGameClient) ListGames(ctx context.Context, req *gamev1.ListGamesRequest) (*gamev1.ListGamesResponse, error) {
return c.app.ListGames(ctx, req)
}
func (c *grpcGameClient) LaunchGame(ctx context.Context, req *gamev1.LaunchGameRequest) (*gamev1.LaunchGameResponse, error) {
return c.app.LaunchGame(ctx, req)
}
func (c *grpcGameClient) HandleCallback(ctx context.Context, req *gamev1.CallbackRequest) (*gamev1.CallbackResponse, error) {
return c.callback.HandleCallback(ctx, req)
}