settings bool

This commit is contained in:
NatureFreshMilk 2019-02-07 09:11:11 +01:00
parent 683c0456e5
commit d960e0404b
5 changed files with 59 additions and 14 deletions

View File

@ -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

View File

@ -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,

View File

@ -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)
}
}

View File

@ -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")
}
}

View File

@ -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)