2014-09-18 07:52:37 +02:00
|
|
|
// Copyright 2014 by Sascha L. Teichmann
|
|
|
|
// Use of this source code is governed by the MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
2014-09-18 15:21:40 +02:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
)
|
2014-09-18 07:52:37 +02:00
|
|
|
|
|
|
|
type tileUpdater struct {
|
|
|
|
mapDir string
|
|
|
|
redisHost string
|
|
|
|
redisPort int
|
|
|
|
}
|
|
|
|
|
2014-09-18 15:21:40 +02:00
|
|
|
type xz struct {
|
|
|
|
X int16
|
|
|
|
Z int16
|
|
|
|
}
|
|
|
|
|
2014-09-18 07:52:37 +02:00
|
|
|
func newTileUpdater(mapDir, redisHost string, redisPort int) *tileUpdater {
|
|
|
|
return &tileUpdater{
|
|
|
|
mapDir: mapDir,
|
|
|
|
redisHost: redisHost,
|
|
|
|
redisPort: redisPort}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tu *tileUpdater) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
2014-09-18 15:21:40 +02:00
|
|
|
var err error
|
|
|
|
var data []xz
|
|
|
|
decoder := json.NewDecoder(r.Body)
|
|
|
|
if err = decoder.Decode(&data); err != nil {
|
|
|
|
log.Printf("WARN: JSON document broken: %s", err)
|
|
|
|
http.Error(rw, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Printf("Changes: #%d %+v\n", len(data), data)
|
|
|
|
rw.WriteHeader(http.StatusOK)
|
2014-09-18 07:52:37 +02:00
|
|
|
}
|