// Package api provides primitives to interact with the openapi HTTP API. // // Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.4.1 DO NOT EDIT. package api import ( "bytes" "compress/gzip" "context" "encoding/base64" "encoding/json" "fmt" "net/http" "net/url" "path" "strings" "github.com/getkin/kin-openapi/openapi3" "github.com/labstack/echo/v4" "github.com/oapi-codegen/nullable" "github.com/oapi-codegen/runtime" strictecho "github.com/oapi-codegen/runtime/strictmiddleware/echo" ) // Defines values for ExecutionStatus. const ( InternalError ExecutionStatus = "internal_error" None ExecutionStatus = "none" Running ExecutionStatus = "running" RuntimeError ExecutionStatus = "runtime_error" Success ExecutionStatus = "success" Timeout ExecutionStatus = "timeout" WrongAnswer ExecutionStatus = "wrong_answer" ) // Defines values for GameGameType. const ( Multiplayer GameGameType = "multiplayer" N1V1 GameGameType = "1v1" ) // Error defines model for Error. type Error struct { Message string `json:"message"` } // ExecutionStatus defines model for ExecutionStatus. type ExecutionStatus string // Game defines model for Game. type Game struct { DisplayName string `json:"display_name"` DurationSeconds int `json:"duration_seconds"` GameID int `json:"game_id"` GameType GameGameType `json:"game_type"` IsPublic bool `json:"is_public"` MainPlayers []User `json:"main_players"` Problem Problem `json:"problem"` StartedAt *int64 `json:"started_at,omitempty"` } // GameGameType defines model for Game.GameType. type GameGameType string // LatestGameState defines model for LatestGameState. type LatestGameState struct { BestScoreSubmittedAt nullable.Nullable[int64] `json:"best_score_submitted_at"` Code string `json:"code"` Score nullable.Nullable[int] `json:"score"` Status ExecutionStatus `json:"status"` } // Problem defines model for Problem. type Problem struct { Description string `json:"description"` ProblemID int `json:"problem_id"` SampleCode string `json:"sample_code"` Title string `json:"title"` } // RankingEntry defines model for RankingEntry. type RankingEntry struct { Code nullable.Nullable[string] `json:"code"` Player User `json:"player"` Score int `json:"score"` SubmittedAt int64 `json:"submitted_at"` } // User defines model for User. type User struct { DisplayName string `json:"display_name"` IconPath *string `json:"icon_path,omitempty"` IsAdmin bool `json:"is_admin"` Label nullable.Nullable[string] `json:"label"` UserID int `json:"user_id"` Username string `json:"username"` } // HeaderAuthorization defines model for header_authorization. type HeaderAuthorization = string // PathGameID defines model for path_game_id. type PathGameID = int // BadRequest defines model for BadRequest. type BadRequest = Error // Forbidden defines model for Forbidden. type Forbidden = Error // NotFound defines model for NotFound. type NotFound = Error // Unauthorized defines model for Unauthorized. type Unauthorized = Error // GetGamesParams defines parameters for GetGames. type GetGamesParams struct { Authorization HeaderAuthorization `json:"Authorization"` } // GetGameParams defines parameters for GetGame. type GetGameParams struct { Authorization HeaderAuthorization `json:"Authorization"` } // PostGamePlayCodeJSONBody defines parameters for PostGamePlayCode. type PostGamePlayCodeJSONBody struct { Code string `json:"code"` } // PostGamePlayCodeParams defines parameters for PostGamePlayCode. type PostGamePlayCodeParams struct { Authorization HeaderAuthorization `json:"Authorization"` } // GetGamePlayLatestStateParams defines parameters for GetGamePlayLatestState. type GetGamePlayLatestStateParams struct { Authorization HeaderAuthorization `json:"Authorization"` } // PostGamePlaySubmitJSONBody defines parameters for PostGamePlaySubmit. type PostGamePlaySubmitJSONBody struct { Code string `json:"code"` } // PostGamePlaySubmitParams defines parameters for PostGamePlaySubmit. type PostGamePlaySubmitParams struct { Authorization HeaderAuthorization `json:"Authorization"` } // GetGameWatchLatestStatesParams defines parameters for GetGameWatchLatestStates. type GetGameWatchLatestStatesParams struct { Authorization HeaderAuthorization `json:"Authorization"` } // GetGameWatchRankingParams defines parameters for GetGameWatchRanking. type GetGameWatchRankingParams struct { Authorization HeaderAuthorization `json:"Authorization"` } // PostLoginJSONBody defines parameters for PostLogin. type PostLoginJSONBody struct { Password string `json:"password"` Username string `json:"username"` } // PostGamePlayCodeJSONRequestBody defines body for PostGamePlayCode for application/json ContentType. type PostGamePlayCodeJSONRequestBody PostGamePlayCodeJSONBody // PostGamePlaySubmitJSONRequestBody defines body for PostGamePlaySubmit for application/json ContentType. type PostGamePlaySubmitJSONRequestBody PostGamePlaySubmitJSONBody // PostLoginJSONRequestBody defines body for PostLogin for application/json ContentType. type PostLoginJSONRequestBody PostLoginJSONBody // ServerInterface represents all server handlers. type ServerInterface interface { // List games // (GET /games) GetGames(ctx echo.Context, params GetGamesParams) error // Get a game // (GET /games/{game_id}) GetGame(ctx echo.Context, gameID PathGameID, params GetGameParams) error // Post the latest code // (POST /games/{game_id}/play/code) PostGamePlayCode(ctx echo.Context, gameID PathGameID, params PostGamePlayCodeParams) error // Get the latest execution result for player // (GET /games/{game_id}/play/latest_state) GetGamePlayLatestState(ctx echo.Context, gameID PathGameID, params GetGamePlayLatestStateParams) error // Submit the answer // (POST /games/{game_id}/play/submit) PostGamePlaySubmit(ctx echo.Context, gameID PathGameID, params PostGamePlaySubmitParams) error // Get all the latest game states of the main players // (GET /games/{game_id}/watch/latest_states) GetGameWatchLatestStates(ctx echo.Context, gameID PathGameID, params GetGameWatchLatestStatesParams) error // Get the latest player ranking // (GET /games/{game_id}/watch/ranking) GetGameWatchRanking(ctx echo.Context, gameID PathGameID, params GetGameWatchRankingParams) error // User login // (POST /login) PostLogin(ctx echo.Context) error } // ServerInterfaceWrapper converts echo contexts to parameters. type ServerInterfaceWrapper struct { Handler ServerInterface } // GetGames converts echo context to params. func (w *ServerInterfaceWrapper) GetGames(ctx echo.Context) error { var err error // Parameter object where we will unmarshal all parameters from the context var params GetGamesParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) } err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err)) } params.Authorization = Authorization } else { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found")) } // Invoke the callback with all the unmarshaled arguments err = w.Handler.GetGames(ctx, params) return err } // GetGame converts echo context to params. func (w *ServerInterfaceWrapper) GetGame(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- var gameID PathGameID err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameID, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter game_id: %s", err)) } // Parameter object where we will unmarshal all parameters from the context var params GetGameParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) } err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err)) } params.Authorization = Authorization } else { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found")) } // Invoke the callback with all the unmarshaled arguments err = w.Handler.GetGame(ctx, gameID, params) return err } // PostGamePlayCode converts echo context to params. func (w *ServerInterfaceWrapper) PostGamePlayCode(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- var gameID PathGameID err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameID, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter game_id: %s", err)) } // Parameter object where we will unmarshal all parameters from the context var params PostGamePlayCodeParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) } err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err)) } params.Authorization = Authorization } else { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found")) } // Invoke the callback with all the unmarshaled arguments err = w.Handler.PostGamePlayCode(ctx, gameID, params) return err } // GetGamePlayLatestState converts echo context to params. func (w *ServerInterfaceWrapper) GetGamePlayLatestState(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- var gameID PathGameID err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameID, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter game_id: %s", err)) } // Parameter object where we will unmarshal all parameters from the context var params GetGamePlayLatestStateParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) } err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err)) } params.Authorization = Authorization } else { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found")) } // Invoke the callback with all the unmarshaled arguments err = w.Handler.GetGamePlayLatestState(ctx, gameID, params) return err } // PostGamePlaySubmit converts echo context to params. func (w *ServerInterfaceWrapper) PostGamePlaySubmit(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- var gameID PathGameID err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameID, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter game_id: %s", err)) } // Parameter object where we will unmarshal all parameters from the context var params PostGamePlaySubmitParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) } err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err)) } params.Authorization = Authorization } else { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found")) } // Invoke the callback with all the unmarshaled arguments err = w.Handler.PostGamePlaySubmit(ctx, gameID, params) return err } // GetGameWatchLatestStates converts echo context to params. func (w *ServerInterfaceWrapper) GetGameWatchLatestStates(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- var gameID PathGameID err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameID, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter game_id: %s", err)) } // Parameter object where we will unmarshal all parameters from the context var params GetGameWatchLatestStatesParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) } err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err)) } params.Authorization = Authorization } else { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found")) } // Invoke the callback with all the unmarshaled arguments err = w.Handler.GetGameWatchLatestStates(ctx, gameID, params) return err } // GetGameWatchRanking converts echo context to params. func (w *ServerInterfaceWrapper) GetGameWatchRanking(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- var gameID PathGameID err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameID, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter game_id: %s", err)) } // Parameter object where we will unmarshal all parameters from the context var params GetGameWatchRankingParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) } err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err)) } params.Authorization = Authorization } else { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found")) } // Invoke the callback with all the unmarshaled arguments err = w.Handler.GetGameWatchRanking(ctx, gameID, params) return err } // PostLogin converts echo context to params. func (w *ServerInterfaceWrapper) PostLogin(ctx echo.Context) error { var err error // Invoke the callback with all the unmarshaled arguments err = w.Handler.PostLogin(ctx) return err } // This is a simple interface which specifies echo.Route addition functions which // are present on both echo.Echo and echo.Group, since we want to allow using // either of them for path registration type EchoRouter interface { CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route } // RegisterHandlers adds each server route to the EchoRouter. func RegisterHandlers(router EchoRouter, si ServerInterface) { RegisterHandlersWithBaseURL(router, si, "") } // Registers handlers, and prepends BaseURL to the paths, so that the paths // can be served under a prefix. func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string) { wrapper := ServerInterfaceWrapper{ Handler: si, } router.GET(baseURL+"/games", wrapper.GetGames) router.GET(baseURL+"/games/:game_id", wrapper.GetGame) router.POST(baseURL+"/games/:game_id/play/code", wrapper.PostGamePlayCode) router.GET(baseURL+"/games/:game_id/play/latest_state", wrapper.GetGamePlayLatestState) router.POST(baseURL+"/games/:game_id/play/submit", wrapper.PostGamePlaySubmit) router.GET(baseURL+"/games/:game_id/watch/latest_states", wrapper.GetGameWatchLatestStates) router.GET(baseURL+"/games/:game_id/watch/ranking", wrapper.GetGameWatchRanking) router.POST(baseURL+"/login", wrapper.PostLogin) } type BadRequestJSONResponse Error type ForbiddenJSONResponse Error type NotFoundJSONResponse Error type UnauthorizedJSONResponse Error type GetGamesRequestObject struct { Params GetGamesParams } type GetGamesResponseObject interface { VisitGetGamesResponse(w http.ResponseWriter) error } type GetGames200JSONResponse struct { Games []Game `json:"games"` } func (response GetGames200JSONResponse) VisitGetGamesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } type GetGames401JSONResponse struct{ UnauthorizedJSONResponse } func (response GetGames401JSONResponse) VisitGetGamesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } type GetGames403JSONResponse struct{ ForbiddenJSONResponse } func (response GetGames403JSONResponse) VisitGetGamesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } type GetGameRequestObject struct { GameID PathGameID `json:"game_id"` Params GetGameParams } type GetGameResponseObject interface { VisitGetGameResponse(w http.ResponseWriter) error } type GetGame200JSONResponse struct { Game Game `json:"game"` } func (response GetGame200JSONResponse) VisitGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } type GetGame401JSONResponse struct{ UnauthorizedJSONResponse } func (response GetGame401JSONResponse) VisitGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } type GetGame403JSONResponse struct{ ForbiddenJSONResponse } func (response GetGame403JSONResponse) VisitGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } type GetGame404JSONResponse struct{ NotFoundJSONResponse } func (response GetGame404JSONResponse) VisitGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(404) return json.NewEncoder(w).Encode(response) } type PostGamePlayCodeRequestObject struct { GameID PathGameID `json:"game_id"` Params PostGamePlayCodeParams Body *PostGamePlayCodeJSONRequestBody } type PostGamePlayCodeResponseObject interface { VisitPostGamePlayCodeResponse(w http.ResponseWriter) error } type PostGamePlayCode200Response struct { } func (response PostGamePlayCode200Response) VisitPostGamePlayCodeResponse(w http.ResponseWriter) error { w.WriteHeader(200) return nil } type PostGamePlayCode401JSONResponse struct{ UnauthorizedJSONResponse } func (response PostGamePlayCode401JSONResponse) VisitPostGamePlayCodeResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } type PostGamePlayCode403JSONResponse struct{ ForbiddenJSONResponse } func (response PostGamePlayCode403JSONResponse) VisitPostGamePlayCodeResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } type PostGamePlayCode404JSONResponse struct{ NotFoundJSONResponse } func (response PostGamePlayCode404JSONResponse) VisitPostGamePlayCodeResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(404) return json.NewEncoder(w).Encode(response) } type GetGamePlayLatestStateRequestObject struct { GameID PathGameID `json:"game_id"` Params GetGamePlayLatestStateParams } type GetGamePlayLatestStateResponseObject interface { VisitGetGamePlayLatestStateResponse(w http.ResponseWriter) error } type GetGamePlayLatestState200JSONResponse struct { State LatestGameState `json:"state"` } func (response GetGamePlayLatestState200JSONResponse) VisitGetGamePlayLatestStateResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } type GetGamePlayLatestState401JSONResponse struct{ UnauthorizedJSONResponse } func (response GetGamePlayLatestState401JSONResponse) VisitGetGamePlayLatestStateResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } type GetGamePlayLatestState403JSONResponse struct{ ForbiddenJSONResponse } func (response GetGamePlayLatestState403JSONResponse) VisitGetGamePlayLatestStateResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } type GetGamePlayLatestState404JSONResponse struct{ NotFoundJSONResponse } func (response GetGamePlayLatestState404JSONResponse) VisitGetGamePlayLatestStateResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(404) return json.NewEncoder(w).Encode(response) } type PostGamePlaySubmitRequestObject struct { GameID PathGameID `json:"game_id"` Params PostGamePlaySubmitParams Body *PostGamePlaySubmitJSONRequestBody } type PostGamePlaySubmitResponseObject interface { VisitPostGamePlaySubmitResponse(w http.ResponseWriter) error } type PostGamePlaySubmit200Response struct { } func (response PostGamePlaySubmit200Response) VisitPostGamePlaySubmitResponse(w http.ResponseWriter) error { w.WriteHeader(200) return nil } type PostGamePlaySubmit401JSONResponse struct{ UnauthorizedJSONResponse } func (response PostGamePlaySubmit401JSONResponse) VisitPostGamePlaySubmitResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } type PostGamePlaySubmit403JSONResponse struct{ ForbiddenJSONResponse } func (response PostGamePlaySubmit403JSONResponse) VisitPostGamePlaySubmitResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } type PostGamePlaySubmit404JSONResponse struct{ NotFoundJSONResponse } func (response PostGamePlaySubmit404JSONResponse) VisitPostGamePlaySubmitResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(404) return json.NewEncoder(w).Encode(response) } type GetGameWatchLatestStatesRequestObject struct { GameID PathGameID `json:"game_id"` Params GetGameWatchLatestStatesParams } type GetGameWatchLatestStatesResponseObject interface { VisitGetGameWatchLatestStatesResponse(w http.ResponseWriter) error } type GetGameWatchLatestStates200JSONResponse struct { States map[string]LatestGameState `json:"states"` } func (response GetGameWatchLatestStates200JSONResponse) VisitGetGameWatchLatestStatesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } type GetGameWatchLatestStates401JSONResponse struct{ UnauthorizedJSONResponse } func (response GetGameWatchLatestStates401JSONResponse) VisitGetGameWatchLatestStatesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } type GetGameWatchLatestStates403JSONResponse struct{ ForbiddenJSONResponse } func (response GetGameWatchLatestStates403JSONResponse) VisitGetGameWatchLatestStatesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } type GetGameWatchLatestStates404JSONResponse struct{ NotFoundJSONResponse } func (response GetGameWatchLatestStates404JSONResponse) VisitGetGameWatchLatestStatesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(404) return json.NewEncoder(w).Encode(response) } type GetGameWatchRankingRequestObject struct { GameID PathGameID `json:"game_id"` Params GetGameWatchRankingParams } type GetGameWatchRankingResponseObject interface { VisitGetGameWatchRankingResponse(w http.ResponseWriter) error } type GetGameWatchRanking200JSONResponse struct { Ranking []RankingEntry `json:"ranking"` } func (response GetGameWatchRanking200JSONResponse) VisitGetGameWatchRankingResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } type GetGameWatchRanking401JSONResponse struct{ UnauthorizedJSONResponse } func (response GetGameWatchRanking401JSONResponse) VisitGetGameWatchRankingResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } type GetGameWatchRanking403JSONResponse struct{ ForbiddenJSONResponse } func (response GetGameWatchRanking403JSONResponse) VisitGetGameWatchRankingResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } type GetGameWatchRanking404JSONResponse struct{ NotFoundJSONResponse } func (response GetGameWatchRanking404JSONResponse) VisitGetGameWatchRankingResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(404) return json.NewEncoder(w).Encode(response) } type PostLoginRequestObject struct { Body *PostLoginJSONRequestBody } type PostLoginResponseObject interface { VisitPostLoginResponse(w http.ResponseWriter) error } type PostLogin200JSONResponse struct { Token string `json:"token"` } func (response PostLogin200JSONResponse) VisitPostLoginResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } type PostLogin401JSONResponse struct{ UnauthorizedJSONResponse } func (response PostLogin401JSONResponse) VisitPostLoginResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } // StrictServerInterface represents all server handlers. type StrictServerInterface interface { // List games // (GET /games) GetGames(ctx context.Context, request GetGamesRequestObject) (GetGamesResponseObject, error) // Get a game // (GET /games/{game_id}) GetGame(ctx context.Context, request GetGameRequestObject) (GetGameResponseObject, error) // Post the latest code // (POST /games/{game_id}/play/code) PostGamePlayCode(ctx context.Context, request PostGamePlayCodeRequestObject) (PostGamePlayCodeResponseObject, error) // Get the latest execution result for player // (GET /games/{game_id}/play/latest_state) GetGamePlayLatestState(ctx context.Context, request GetGamePlayLatestStateRequestObject) (GetGamePlayLatestStateResponseObject, error) // Submit the answer // (POST /games/{game_id}/play/submit) PostGamePlaySubmit(ctx context.Context, request PostGamePlaySubmitRequestObject) (PostGamePlaySubmitResponseObject, error) // Get all the latest game states of the main players // (GET /games/{game_id}/watch/latest_states) GetGameWatchLatestStates(ctx context.Context, request GetGameWatchLatestStatesRequestObject) (GetGameWatchLatestStatesResponseObject, error) // Get the latest player ranking // (GET /games/{game_id}/watch/ranking) GetGameWatchRanking(ctx context.Context, request GetGameWatchRankingRequestObject) (GetGameWatchRankingResponseObject, error) // User login // (POST /login) PostLogin(ctx context.Context, request PostLoginRequestObject) (PostLoginResponseObject, error) } type StrictHandlerFunc = strictecho.StrictEchoHandlerFunc type StrictMiddlewareFunc = strictecho.StrictEchoMiddlewareFunc func NewStrictHandler(ssi StrictServerInterface, middlewares []StrictMiddlewareFunc) ServerInterface { return &strictHandler{ssi: ssi, middlewares: middlewares} } type strictHandler struct { ssi StrictServerInterface middlewares []StrictMiddlewareFunc } // GetGames operation middleware func (sh *strictHandler) GetGames(ctx echo.Context, params GetGamesParams) error { var request GetGamesRequestObject request.Params = params handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.GetGames(ctx.Request().Context(), request.(GetGamesRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "GetGames") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(GetGamesResponseObject); ok { return validResponse.VisitGetGamesResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // GetGame operation middleware func (sh *strictHandler) GetGame(ctx echo.Context, gameID PathGameID, params GetGameParams) error { var request GetGameRequestObject request.GameID = gameID request.Params = params handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.GetGame(ctx.Request().Context(), request.(GetGameRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "GetGame") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(GetGameResponseObject); ok { return validResponse.VisitGetGameResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // PostGamePlayCode operation middleware func (sh *strictHandler) PostGamePlayCode(ctx echo.Context, gameID PathGameID, params PostGamePlayCodeParams) error { var request PostGamePlayCodeRequestObject request.GameID = gameID request.Params = params var body PostGamePlayCodeJSONRequestBody if err := ctx.Bind(&body); err != nil { return err } request.Body = &body handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.PostGamePlayCode(ctx.Request().Context(), request.(PostGamePlayCodeRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "PostGamePlayCode") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(PostGamePlayCodeResponseObject); ok { return validResponse.VisitPostGamePlayCodeResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // GetGamePlayLatestState operation middleware func (sh *strictHandler) GetGamePlayLatestState(ctx echo.Context, gameID PathGameID, params GetGamePlayLatestStateParams) error { var request GetGamePlayLatestStateRequestObject request.GameID = gameID request.Params = params handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.GetGamePlayLatestState(ctx.Request().Context(), request.(GetGamePlayLatestStateRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "GetGamePlayLatestState") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(GetGamePlayLatestStateResponseObject); ok { return validResponse.VisitGetGamePlayLatestStateResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // PostGamePlaySubmit operation middleware func (sh *strictHandler) PostGamePlaySubmit(ctx echo.Context, gameID PathGameID, params PostGamePlaySubmitParams) error { var request PostGamePlaySubmitRequestObject request.GameID = gameID request.Params = params var body PostGamePlaySubmitJSONRequestBody if err := ctx.Bind(&body); err != nil { return err } request.Body = &body handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.PostGamePlaySubmit(ctx.Request().Context(), request.(PostGamePlaySubmitRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "PostGamePlaySubmit") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(PostGamePlaySubmitResponseObject); ok { return validResponse.VisitPostGamePlaySubmitResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // GetGameWatchLatestStates operation middleware func (sh *strictHandler) GetGameWatchLatestStates(ctx echo.Context, gameID PathGameID, params GetGameWatchLatestStatesParams) error { var request GetGameWatchLatestStatesRequestObject request.GameID = gameID request.Params = params handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.GetGameWatchLatestStates(ctx.Request().Context(), request.(GetGameWatchLatestStatesRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "GetGameWatchLatestStates") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(GetGameWatchLatestStatesResponseObject); ok { return validResponse.VisitGetGameWatchLatestStatesResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // GetGameWatchRanking operation middleware func (sh *strictHandler) GetGameWatchRanking(ctx echo.Context, gameID PathGameID, params GetGameWatchRankingParams) error { var request GetGameWatchRankingRequestObject request.GameID = gameID request.Params = params handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.GetGameWatchRanking(ctx.Request().Context(), request.(GetGameWatchRankingRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "GetGameWatchRanking") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(GetGameWatchRankingResponseObject); ok { return validResponse.VisitGetGameWatchRankingResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // PostLogin operation middleware func (sh *strictHandler) PostLogin(ctx echo.Context) error { var request PostLoginRequestObject var body PostLoginJSONRequestBody if err := ctx.Bind(&body); err != nil { return err } request.Body = &body handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.PostLogin(ctx.Request().Context(), request.(PostLoginRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "PostLogin") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(PostLoginResponseObject); ok { return validResponse.VisitPostLoginResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ "H4sIAAAAAAAC/+xYW2/UuBf/Kpb/f4mX0ExpVbHdp7ILiBVCI1i0WiEUeZIzMy6OHWyH6SzKd1/Zzs2J", "00kLZbfV9qGa2D73n8/FX3Eq8kJw4Frh86+4IJLkoEHary2QDGRCSr0Vkv5FNBXcrFOOz+tNHGFOcsDn", "+MI7FWEJn0sqIcPnWpYQYZVuISeGXO8LQ6C0pHyDqyrCBdHbZENySGjWCjCLHftmdwZjyjVsQOLKsJag", "CsEVWIOekewtfC5BafOVCq6B25+kKBhNrerxpXJWdnz/L2GNz/H/4s5ZsdtV8XMpRS0qA5VKWjgvGVlI", "1sKqCL8QckWzDPjdS+5EVRF+I/QLUfLs7sW+ERqtragqwu95gxr4AaI9aWa7pjAMHZHBthQFSE0dFHJQ", "imzA/IQrkhfMIOcV/0IY7eIWBbDawe9Dy+Rje1CsLiG1AX9+BWlp9HuniS6tTOBlbsi44GCAXHJuuEZY", "lWkKSuEI76Tgm4RwtbN3S9McRKndYfORgDUnsiCXnLB64WPUM6NjN1A/wi/tbRo6I6OqYGSf8Hq3Y2XO", "o+MQp6yUNoaJglTwTHl0J2eLaHQdI9y74u3R48mDbrlz2/EXo0heMk2NtjCw2m2P9KQqKcoVo6kn1aWO", "+vBKCAbEXpecUJ447tYiqiFXh3D5Xjmta3ZESrI334UUKwb5IfJlfczgVhOpIUuI9rT96fTs7Onp08XY", "qRG+erwRj7vVs9MRSrvU2bm175fIj38gtJ0pAw+FgP+aaFDaAMcgP4C2FSidqFRISFS5yqm+3mJeMkZW", "o6Bd64EIpyIbQBnSrUCPtsCYQDshWfbo5xBerGI+Qmdo4WJX3/Nrc9ggLQyDZfVutIgmfdWKC0Vg2eFu", "cM/7WbPvm9+3VCGqEEFdoEeeqbdmXWBlN5NbR0FTzQaUtVWhbDTwYU/RhpNfMXz9Qi58S/gnyjfPuZb7", "sR/nmjUBmp5LXR6bmV8moBnw/oxrdYtEUmvboXMAyUlvWgNuUHV+E1uOfhUQzOep4IntDT2SmOZkAyq+", "FFt+dFlsJkoByXLqY39NmAqWAkZWwHwhSpP1ek5cSwVydE+enIRiZY6OPWDMOIjzRkqPySiXtzY3Bo3j", "Y9hSvha2hXb3Dl+wFdFSKIWaRgPtYIUulq9whL+AVK7xWhwdHy2MFaIATgqKz/HJ0eJogV1Pb8Mcm6pj", "f23AotFgwNaXV5npMMDWCltketPHh/CV6I7Ewemk+jho+Z8sFjfqP32ItqrP6gNsczXqAwLVWE1Ewe9q", "X1OlkVgjR1FF+HRxPKVCa3Ps98KG6OQwUW9ksOkjz4nJe06FWn4V1aGMv9YdRXUoqN8pptFBOm+AvAMM", "zIt8INKzAn1hXfzDImwoTg9TtJOjD4mXoBGpFQ5AIjbJJ24KZCFUAB1L4frDJSP7X1y/84/BxA56z0S2", "/waE3LLLCXV+Ybj4Tx5VGN4+pt65GXBdMrZHZZER3YDlX48wAw+kt4CYnSSQdcw01typRDXDxnUJySDO", "zSduNnkI+ak1/LoENRzKhuBzTOYkqz9FKZvIGIuQI70/yauHLGiGMSRBlUyjtZCo7nKnAee63nnp7Z07", "+1+Cu9sE1w4i9wSHDhYWivVbXxBuO6LTrZfgDvbRfxiSXopTDyfH2V8ky6ghIWzpnbhR8htjMJAN5zXp", "F4z1M0qXEZVp3c1OTihHzYPZPerxbmjYNH6le0uZhdz63eVBgLZn96zx0XtzOjRGNsznYHRpY4QakntZ", "qouBDQZuTGzcY850HX5tj3yvOlgQpXZC+u867erxkxM88Rb0DQ88vJmja9HfUEBvabUWn2DwXnxl/o56", "/w+a4pjMQatX2A0CgWuj6q2Luwer9wokcsCpqqr6OwAA//9YsFelAR8AAA==", } // GetSwagger returns the content of the embedded swagger specification file // or error if failed to decode func decodeSpec() ([]byte, error) { zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, "")) if err != nil { return nil, fmt.Errorf("error base64 decoding spec: %w", err) } zr, err := gzip.NewReader(bytes.NewReader(zipped)) if err != nil { return nil, fmt.Errorf("error decompressing spec: %w", err) } var buf bytes.Buffer _, err = buf.ReadFrom(zr) if err != nil { return nil, fmt.Errorf("error decompressing spec: %w", err) } return buf.Bytes(), nil } var rawSpec = decodeSpecCached() // a naive cached of a decoded swagger spec func decodeSpecCached() func() ([]byte, error) { data, err := decodeSpec() return func() ([]byte, error) { return data, err } } // Constructs a synthetic filesystem for resolving external references when loading openapi specifications. func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) { res := make(map[string]func() ([]byte, error)) if len(pathToFile) > 0 { res[pathToFile] = rawSpec } return res } // GetSwagger returns the Swagger specification corresponding to the generated code // in this file. The external references of Swagger specification are resolved. // The logic of resolving external references is tightly connected to "import-mapping" feature. // Externally referenced files must be embedded in the corresponding golang packages. // Urls can be supported but this task was out of the scope. func GetSwagger() (swagger *openapi3.T, err error) { resolvePath := PathToRawSpec("") loader := openapi3.NewLoader() loader.IsExternalRefsAllowed = true loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) { pathToFile := url.String() pathToFile = path.Clean(pathToFile) getSpec, ok := resolvePath[pathToFile] if !ok { err1 := fmt.Errorf("path not found: %s", pathToFile) return nil, err1 } return getSpec() } var specData []byte specData, err = rawSpec() if err != nil { return } swagger, err = loader.LoadFromData(specData) if err != nil { return } return }