diff --git a/control.go b/control.go index feb26bc..4f0280e 100644 --- a/control.go +++ b/control.go @@ -10,6 +10,7 @@ import ( "os" "runtime/pprof" "strings" + "sync" ) type JsonHandler func(http.ResponseWriter, *http.Request) @@ -252,3 +253,24 @@ func (c *Controller) getGameId(path string) (string, error) { key := fullPath[2] return key, err } + +type MapLock struct { + M map[string]*Game + sync.RWMutex +} + +// get is a function that returns a game if found, and creates one if +// not found and force is true. In order to get a hash (rather than use +// the string you pass) send "" for id. +func (ml *MapLock) get(id string) *Game { + ml.Lock() + g, _ := ml.M[id] + ml.Unlock() + return g +} + +func (ml *MapLock) add(g *Game) { + ml.Lock() + ml.M[g.id] = g + ml.Unlock() +} diff --git a/game.go b/game.go index fba3e2d..ad4e794 100644 --- a/game.go +++ b/game.go @@ -23,27 +23,6 @@ type Scanner struct { Type string `json:"type"` } -type MapLock struct { - M map[string]*Game - sync.RWMutex -} - -// get is a function that returns a game if found, and creates one if -// not found and force is true. In order to get a hash (rather than use -// the string you pass) send "" for id. -func (ml *MapLock) get(id string) *Game { - ml.Lock() - g, _ := ml.M[id] - ml.Unlock() - return g -} - -func (ml *MapLock) add(g *Game) { - ml.Lock() - ml.M[g.id] = g - ml.Unlock() -} - type BotStats struct { Kills int Deaths int