Skip to content
Snippets Groups Projects
Commit d11c704f authored by Alex Constantin-Gomez's avatar Alex Constantin-Gomez
Browse files

added generateID() - not thread safe

parent e0d3b299
No related branches found
No related tags found
No related merge requests found
......@@ -17,8 +17,8 @@ type Player struct {
// Game represents a game object in the database
type Game struct {
ID int
Player1 Player
Player2 Player
Player1 string
Player2 string
}
// Move represents a move in the game
......@@ -30,12 +30,14 @@ type Move struct {
}
var (
gameData map[int]Game
gameData map[int]Game
idCounter int
)
/************** MAIN FUNCTION **********************/
func main() {
// Initialise global variables
gameData = make(map[int]Game)
http.HandleFunc("/", hello)
......@@ -73,9 +75,25 @@ func move(w http.ResponseWriter, r *http.Request) {
}
func createGame(w http.ResponseWriter, r *http.Request) {
//jsonData := readJsonFromRequest(r)
newGameID := generateID()
newGame := Game{
ID: newGameID,
// Player1: ,
// Player2: ,
}
gameData[newGameID] = newGame
fmt.Fprintf(w, "hello")
}
func joinGame(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "hello")
}
/************** Helper functions *******************/
func generateID() int {
return idCounter + 1
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment