1
0
forked from MTSR/mapserver
mapserver/server/settings/settings.go
NatureFreshMilk 683c0456e5 settings type
2019-02-07 09:02:15 +01:00

83 lines
1.5 KiB
Go

package settings
import (
"mapserver/mapobjectdb"
"strconv"
)
const (
SETTING_LAST_MTIME = "last_mtime"
SETTING_LASTX = "last_x"
SETTING_LASTY = "last_y"
SETTING_LASTZ = "last_z"
SETTING_INITIAL_RUN = "initial_run"
)
type Settings struct {
db mapobjectdb.DBAccessor
}
func New(db mapobjectdb.DBAccessor) *Settings{
return &Settings{
db: db,
}
}
func (this *Settings) GetString(key string, defaultValue string) string {
str, err := this.db.GetSetting(key, defaultValue)
if err != nil {
panic(err)
}
return str
}
func (this *Settings) SetString(key string, value string) {
err := this.db.SetSetting(key, value)
if err != nil {
panic(err)
}
}
func (this *Settings) GetInt(key string, defaultValue int) int {
str, err := this.db.GetSetting(key, strconv.Itoa(defaultValue))
if err != nil {
panic(err)
}
value, err := strconv.Atoi(str)
if err != nil {
panic(err)
}
return value
}
func (this *Settings) SetInt(key string, value int) {
err := this.db.SetSetting(key, strconv.Itoa(value))
if err != nil {
panic(err)
}
}
func (this *Settings) GetInt64(key string, defaultValue int64) int64 {
str, err := this.db.GetSetting(key, strconv.FormatInt(defaultValue, 10))
if err != nil {
panic(err)
}
value, err := strconv.ParseInt(str, 10, 64)
if err != nil {
panic(err)
}
return value
}
func (this *Settings) SetInt64(key string, value int64) {
err := this.db.SetSetting(key, strconv.FormatInt(value, 10))
if err != nil {
panic(err)
}
}