Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BTT-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florin-Teodor Ruja
BTT-backend
Commits
d11c704f
Commit
d11c704f
authored
5 years ago
by
Alex Constantin-Gomez
Browse files
Options
Downloads
Patches
Plain Diff
added generateID() - not thread safe
parent
e0d3b299
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.go
+21
-3
21 additions, 3 deletions
main.go
with
21 additions
and
3 deletions
main.go
+
21
−
3
View file @
d11c704f
...
...
@@ -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
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment