Skip to content

A simple matchmaking-like service written in GO using gorilla request router.

Notifications You must be signed in to change notification settings

L4ZZA/matchmaking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Matchmaking REST service

Preamble

A simple matchmaking-like service written in GO using gorilla request router.

Instructions

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 requests
    • curl localhost:9090/route -XPOST -d '{"json":"data"}' for POST requests with a body
    • curl localhost:9090/route -XDELETE for DELETE requests.

User API

The service can be access through three main entry points:

  • sessions
  • join
  • leave

Sessions

The /session handle will return all the sessions that are currently running or that are awaiting more players.

example: curl localhost:9090/sessions

Join

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"}'

/leave

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

About

A simple matchmaking-like service written in GO using gorilla request router.

Resources

Stars

Watchers

Forks

Languages