Dont lock the player list all the time when serving the GeoJSON over /players.

This commit is contained in:
Sascha L. Teichmann 2015-03-09 16:05:54 +01:00
parent c918b538db
commit 28fc4d0734

View File

@ -86,10 +86,12 @@ func (ps *players) run() {
func (ps *players) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
rw.Header().Set("Content-Type", "application/json")
var pls []*player
ps.mu.RLock()
defer ps.mu.RUnlock()
pls = ps.pls
ps.mu.RUnlock()
encoder := json.NewEncoder(rw)
if err := encoder.Encode(ps.pls); err != nil {
if err := encoder.Encode(pls); err != nil {
log.Printf("error: sending JSON failed: %s\n", err)
}
}