simple map for world config

This commit is contained in:
NatureFreshMilk 2019-02-08 14:57:36 +01:00
parent 10d6e8904d
commit d710159bf8
4 changed files with 10 additions and 37 deletions

View File

@ -10,7 +10,6 @@ import (
"mapserver/settings"
"mapserver/params"
"mapserver/tilerenderer"
"mapserver/worldconfig"
)
const (
@ -20,7 +19,7 @@ const (
type App struct {
Params params.ParamsType
Config *Config
Worldconfig worldconfig.WorldConfig
Worldconfig map[string]string
Blockdb db.DBAccessor
Objectdb mapobjectdb.DBAccessor

View File

@ -32,14 +32,14 @@ func Setup(p params.ParamsType, cfg *Config) *App {
var err error
switch a.Worldconfig.Backend {
switch a.Worldconfig[worldconfig.CONFIG_BACKEND] {
case worldconfig.BACKEND_SQLITE3:
a.Blockdb, err = sqlite.New("map.sqlite")
if err != nil {
panic(err)
}
default:
panic(errors.New("map-backend not supported: " + a.Worldconfig.Backend))
panic(errors.New("map-backend not supported: " + a.Worldconfig[worldconfig.CONFIG_BACKEND]))
}
//migrate block db
@ -85,7 +85,7 @@ func Setup(p params.ParamsType, cfg *Config) *App {
a.Mapblockrenderer = mapblockrenderer.NewMapBlockRenderer(a.BlockAccessor, a.Colormapping)
//mapserver database
if a.Worldconfig.MapObjectConnection != "" {
if a.Worldconfig[worldconfig.CONFIG_PSQL_MAPSERVER] != "" {
//TODO: Psql connection
} else {

View File

@ -19,30 +19,14 @@ const (
CONFIG_PSQL_MAPSERVER string = "pgsql_mapserver_connection"
)
type PsqlConfig struct {
Host string
Port int
Username string
Password string
DbName string
}
type WorldConfig struct {
Backend string
PlayerBackend string
PsqlConnection string
MapObjectConnection string
}
func Parse(filename string) WorldConfig {
func Parse(filename string) map[string]string {
file, err := os.Open(filename)
if err != nil {
panic(err)
}
defer file.Close()
cfg := WorldConfig{}
cfg := make(map[string]string)
scanner := bufio.NewScanner(file)
for scanner.Scan() {
@ -55,17 +39,7 @@ func Parse(filename string) WorldConfig {
valueStr := strings.Trim(line[sepIndex+1:], " ")
keyStr := strings.Trim(line[:sepIndex], " ")
switch keyStr {
case CONFIG_BACKEND:
cfg.Backend = valueStr
case CONFIG_PLAYER_BACKEND:
cfg.PlayerBackend = valueStr
case CONFIG_PSQL_CONNECTION:
cfg.PsqlConnection = valueStr
case CONFIG_PSQL_MAPSERVER:
cfg.MapObjectConnection = valueStr
}
cfg[keyStr] = valueStr
}
return cfg

View File

@ -7,7 +7,7 @@ import (
func TestParseSqlite(t *testing.T) {
cfg := Parse("./testdata/world.mt.sqlite")
if cfg.Backend != BACKEND_SQLITE3 {
if cfg[CONFIG_BACKEND] != BACKEND_SQLITE3 {
t.Fatal("not sqlite3")
}
}
@ -15,11 +15,11 @@ func TestParseSqlite(t *testing.T) {
func TestParsePostgres(t *testing.T) {
cfg := Parse("./testdata/world.mt.postgres")
fmt.Println(cfg)
if cfg.Backend != BACKEND_POSTGRES {
if cfg[CONFIG_BACKEND] != BACKEND_POSTGRES {
t.Fatal("not postgres")
}
if cfg.PsqlConnection != "host=postgres port=5432 user=postgres password=enter dbname=postgres" {
if cfg[CONFIG_PSQL_CONNECTION] != "host=postgres port=5432 user=postgres password=enter dbname=postgres" {
t.Fatal("param err")
}
}