func GameSessionData()

in containers-starter-kit/SdkGoWrapper/server.go [92:123]


func GameSessionData(w http.ResponseWriter, req *http.Request) {

        // If UpdateGameSessionData GameSessionId is not empty, return the updated data
        // NOTE: We're not returning the UpdateReason or BackfillTicketID that are also included in an UpdateGameSession, just the game session data itself
        if UpdateGameSession.GameSession.GameSessionID != "" {
                log.Print("Returning Updated GameSessionData")
                jsonBytes, err := json.Marshal(UpdateGameSession.GameSession)
                if err != nil {
                        fmt.Println("Error:", err)
                        // Set the response status code to 500 (Internal Server Error)
                        w.WriteHeader(http.StatusInternalServerError)
                        fmt.Fprintf(w, "error\n")
                        return
                }
                w.Header().Set("Content-Type", "application/json")
                fmt.Fprintf(w, string(jsonBytes))
                return
        }

        // else try to return the initial game session data (could be empty values but that's fine, client can handle that)
        log.Print("Returning GameSessionData")
        jsonBytes, err := json.Marshal(GameSession)
        if err != nil {
                fmt.Println("Error:", err)
                // Set the response status code to 500 (Internal Server Error)
                w.WriteHeader(http.StatusInternalServerError)
                fmt.Fprintf(w, "error\n")
                return
        }
        w.Header().Set("Content-Type", "application/json")
        fmt.Fprintf(w, string(jsonBytes))
}