A simple matchmaking-like service written in GO using gorilla request router.
I am assuming that you already have Go installed and working on your machine
- Unzip to a subdirectory of you GOPATH environment variable.
- Open a terminal\shell inside the api folder.
- Run
go run main.go
to start the server - Use curl to send HTTP requests to the server:
curl localhost:9090/route
for GET requestscurl localhost:9090/route -XPOST -d '{"json":"data"}'
for POST requests with a bodycurl localhost:9090/route -XDELETE
for DELETE requests.
The service can be access through three main entry points:
sessions
join
leave
The /session
handle will return all the sessions that are currently running or that are awaiting more players.
example: curl localhost:9090/sessions
The /join
handle will allow a player to join a session and wait for the match to start. If no sessions are available a new one will be generated for the player.
This message requires a Player JSON object with a name defined or the player will not be added.
The id is automatically generated.
Player format
type Player struct {
ID int `json:"id"`
Name string `json:"name" validate:"required"`
SessionID int `json:"session_id"`
CreatedOn string `json:"-"`
UpdatedOn string `json:"-"`
DeletedOn string `json:"-"`
}
example: curl localhost:9090/join -XPOST -d '{"name":"Player"}'
The /leave
handle will allow a player to leave a session.
If the session will drop under the minimum allowed players it will be stopped and the remaining players will be joined to all other awaiting players.
If in this process the maximum players limit per session is reached, the the players that can't fit in that session will be added to a new one.
The leave handle will require the id of the player to be passes after the leave handle ( i.e. /leave/15
) or the request will be denied.
example: curl localhost:9090/leave/9 -XDELETE