71 lines
2.2 KiB
Go
71 lines
2.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
|
||
// 热游固定回调地址先进入 hyapp gateway;chatapp3 老 token 需要原样转给 chatapp3,hyapp token 继续落到 game-service。
|
||
hotgameCompatHTTPClient *http.Client
|
||
}
|
||
|
||
type Config struct {
|
||
GameClient client.GameClient
|
||
UserProfileClient client.UserProfileClient
|
||
}
|
||
|
||
func New(config Config) *Handler {
|
||
return &Handler{
|
||
gameClient: config.GameClient,
|
||
userProfileClient: config.UserProfileClient,
|
||
hotgameCompatHTTPClient: hotgameCompatHTTPClient(),
|
||
}
|
||
}
|
||
|
||
func (h *Handler) Handlers() httproutes.GameHandlers {
|
||
return httproutes.GameHandlers{
|
||
ListGames: h.listGames,
|
||
ListRecentGames: h.listRecentGames,
|
||
GetBridgeScript: h.getBridgeScript,
|
||
LaunchGame: h.launchGame,
|
||
HandleCallback: h.handleGameCallback,
|
||
HandleHotgameGetUserInfo: h.handleHotgameGetUserInfo,
|
||
HandleHotgameUpdateBalance: h.handleHotgameUpdateBalance,
|
||
}
|
||
}
|
||
|
||
func (h *Handler) ListGames(writer http.ResponseWriter, request *http.Request) {
|
||
h.listGames(writer, request)
|
||
}
|
||
|
||
func (h *Handler) ListRecentGames(writer http.ResponseWriter, request *http.Request) {
|
||
h.listRecentGames(writer, request)
|
||
}
|
||
|
||
func (h *Handler) GetBridgeScript(writer http.ResponseWriter, request *http.Request) {
|
||
h.getBridgeScript(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)
|
||
}
|
||
|
||
func (h *Handler) HandleHotgameGetUserInfo(writer http.ResponseWriter, request *http.Request) {
|
||
h.handleHotgameGetUserInfo(writer, request)
|
||
}
|
||
|
||
func (h *Handler) HandleHotgameUpdateBalance(writer http.ResponseWriter, request *http.Request) {
|
||
h.handleHotgameUpdateBalance(writer, request)
|
||
}
|