diff --git a/server/app/app.go b/server/app/app.go index ad44451..2d81260 100644 --- a/server/app/app.go +++ b/server/app/app.go @@ -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 diff --git a/server/app/setup.go b/server/app/setup.go index 26a1815..8ebfea9 100644 --- a/server/app/setup.go +++ b/server/app/setup.go @@ -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 { diff --git a/server/worldconfig/parse.go b/server/worldconfig/parse.go index 4b36cad..6161222 100644 --- a/server/worldconfig/parse.go +++ b/server/worldconfig/parse.go @@ -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 diff --git a/server/worldconfig/parse_test.go b/server/worldconfig/parse_test.go index daec3e9..c2c1caa 100644 --- a/server/worldconfig/parse_test.go +++ b/server/worldconfig/parse_test.go @@ -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") } }