diff --git a/server/app/app.go b/server/app/app.go index dbb76d0..ad44451 100644 --- a/server/app/app.go +++ b/server/app/app.go @@ -7,6 +7,7 @@ import ( "mapserver/mapblockaccessor" "mapserver/mapblockrenderer" "mapserver/mapobjectdb" + "mapserver/settings" "mapserver/params" "mapserver/tilerenderer" "mapserver/worldconfig" @@ -23,6 +24,7 @@ type App struct { Blockdb db.DBAccessor Objectdb mapobjectdb.DBAccessor + Settings *settings.Settings BlockAccessor *mapblockaccessor.MapBlockAccessor Colormapping *colormapping.ColorMapping diff --git a/server/app/setup.go b/server/app/setup.go index ef6b785..2e7c814 100644 --- a/server/app/setup.go +++ b/server/app/setup.go @@ -10,6 +10,7 @@ import ( "mapserver/params" "mapserver/tilerenderer" "mapserver/worldconfig" + "mapserver/settings" "github.com/sirupsen/logrus" @@ -63,7 +64,6 @@ func Setup(p params.ParamsType, cfg *Config) *App { } else { a.Objectdb, err = sqliteobjdb.New("mapserver.sqlite") - } if err != nil { @@ -77,6 +77,9 @@ func Setup(p params.ParamsType, cfg *Config) *App { panic(err) } + //settings + a.Settings = settings.New(a.Objectdb) + //setup tile renderer a.Tilerenderer = tilerenderer.NewTileRenderer( a.Mapblockrenderer, diff --git a/server/settings/settings.go b/server/settings/settings.go index 121c5d1..e9727b9 100644 --- a/server/settings/settings.go +++ b/server/settings/settings.go @@ -80,3 +80,30 @@ func (this *Settings) SetInt64(key string, value int64) { panic(err) } } + + +func (this *Settings) GetBool(key string, defaultValue bool) bool { + defStr := "false" + if defaultValue { + defStr = "true" + } + + str, err := this.db.GetSetting(key, defStr) + if err != nil { + panic(err) + } + + return str == "true" +} + +func (this *Settings) SetBool(key string, value bool) { + defStr := "false" + if value { + defStr = "true" + } + + err := this.db.SetSetting(key, defStr) + if err != nil { + panic(err) + } +} diff --git a/server/settings/settings_test.go b/server/settings/settings_test.go index 18e125f..311d570 100644 --- a/server/settings/settings_test.go +++ b/server/settings/settings_test.go @@ -25,6 +25,9 @@ func TestStrings(t *testing.T){ } s := New(db) + + //string + s.SetString("k", "v") str := s.GetString("k", "v2") if str != "v" { @@ -35,6 +38,8 @@ func TestStrings(t *testing.T){ t.Fatal("getstring with default failed") } + //int + s.SetInt("i", 123) i := s.GetInt("i", 456) if i != 123 { @@ -45,6 +50,8 @@ func TestStrings(t *testing.T){ t.Fatal("getint with default failed") } + //int64 + s.SetInt64("i", 1230000012300056) i2 := s.GetInt64("i", 456) if i2 != 1230000012300056 { @@ -55,4 +62,20 @@ func TestStrings(t *testing.T){ t.Fatal("getint with default failed") } + //bool + + s.SetBool("b", false) + b2 := s.GetBool("b", true) + if b2 { + t.Fatal("getbool failed") + } + + if s.GetBool("b2", false) { + t.Fatal("getbool with default failed") + } + + if !s.GetBool("b2", true) { + t.Fatal("getbool with default failed") + } + } diff --git a/server/tilerendererjob/incremental.go b/server/tilerendererjob/incremental.go index d0b72f6..70eba26 100644 --- a/server/tilerendererjob/incremental.go +++ b/server/tilerendererjob/incremental.go @@ -3,10 +3,8 @@ package tilerendererjob import ( "mapserver/app" "mapserver/coords" - "mapserver/mapobjectdb" + "mapserver/settings" "time" - "strconv" - "github.com/sirupsen/logrus" ) @@ -16,15 +14,7 @@ type IncrementalRenderEvent struct { func incrementalRender(ctx *app.App, jobs chan *coords.TileCoords) { - str, err := ctx.Objectdb.GetSetting(mapobjectdb.SETTING_LAST_MTIME, "0") - if err != nil { - panic(err) - } - - lastMtime, err := strconv.ParseInt(str, 10, 64) - if err != nil { - panic(err) - } + lastMtime := ctx.Settings.GetInt64(settings.SETTING_LAST_MTIME, 0) fields := logrus.Fields{ "LastMtime": lastMtime, @@ -46,7 +36,7 @@ func incrementalRender(ctx *app.App, jobs chan *coords.TileCoords) { } lastMtime = result.LastMtime - ctx.Objectdb.SetSetting(mapobjectdb.SETTING_LAST_MTIME, strconv.FormatInt(lastMtime, 10)) + ctx.Settings.GetInt64(settings.SETTING_LAST_MTIME, lastMtime) tiles := renderMapblocks(ctx, jobs, result.List)