48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package gameapi
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"hyapp/services/gateway-service/internal/client"
|
|
"hyapp/services/gateway-service/internal/transport/http/httproutes"
|
|
)
|
|
|
|
// Handler owns game-facing HTTP endpoints.
|
|
// gateway only translates app/user context into game-service RPCs; game session state stays in game-service.
|
|
type Handler struct {
|
|
gameClient client.GameClient
|
|
userProfileClient client.UserProfileClient
|
|
}
|
|
|
|
type Config struct {
|
|
GameClient client.GameClient
|
|
UserProfileClient client.UserProfileClient
|
|
}
|
|
|
|
func New(config Config) *Handler {
|
|
return &Handler{
|
|
gameClient: config.GameClient,
|
|
userProfileClient: config.UserProfileClient,
|
|
}
|
|
}
|
|
|
|
func (h *Handler) Handlers() httproutes.GameHandlers {
|
|
return httproutes.GameHandlers{
|
|
ListGames: h.listGames,
|
|
LaunchGame: h.launchGame,
|
|
HandleCallback: h.handleGameCallback,
|
|
}
|
|
}
|
|
|
|
func (h *Handler) ListGames(writer http.ResponseWriter, request *http.Request) {
|
|
h.listGames(writer, request)
|
|
}
|
|
|
|
func (h *Handler) LaunchGame(writer http.ResponseWriter, request *http.Request) {
|
|
h.launchGame(writer, request)
|
|
}
|
|
|
|
func (h *Handler) HandleCallback(writer http.ResponseWriter, request *http.Request) {
|
|
h.handleGameCallback(writer, request)
|
|
}
|