From 3f13738d415caad3c93cfc63e444eb206d216a6b Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Thu, 18 Sep 2014 15:21:40 +0200 Subject: [PATCH] Initial decoding from incoming block changes. --- cmd/mtwebmapper/tilesupdater.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cmd/mtwebmapper/tilesupdater.go b/cmd/mtwebmapper/tilesupdater.go index 2f8f75d..1a8e712 100644 --- a/cmd/mtwebmapper/tilesupdater.go +++ b/cmd/mtwebmapper/tilesupdater.go @@ -4,7 +4,11 @@ package main -import "net/http" +import ( + "encoding/json" + "log" + "net/http" +) type tileUpdater struct { mapDir string @@ -12,6 +16,11 @@ type tileUpdater struct { redisPort int } +type xz struct { + X int16 + Z int16 +} + func newTileUpdater(mapDir, redisHost string, redisPort int) *tileUpdater { return &tileUpdater{ mapDir: mapDir, @@ -21,5 +30,14 @@ func newTileUpdater(mapDir, redisHost string, redisPort int) *tileUpdater { } func (tu *tileUpdater) ServeHTTP(rw http.ResponseWriter, r *http.Request) { - // TODO: Implement me! + 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) }