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

View File

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

View File

@ -19,30 +19,14 @@ const (
CONFIG_PSQL_MAPSERVER string = "pgsql_mapserver_connection" CONFIG_PSQL_MAPSERVER string = "pgsql_mapserver_connection"
) )
type PsqlConfig struct { func Parse(filename string) map[string]string {
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 {
file, err := os.Open(filename) file, err := os.Open(filename)
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer file.Close() defer file.Close()
cfg := WorldConfig{} cfg := make(map[string]string)
scanner := bufio.NewScanner(file) scanner := bufio.NewScanner(file)
for scanner.Scan() { for scanner.Scan() {
@ -55,17 +39,7 @@ func Parse(filename string) WorldConfig {
valueStr := strings.Trim(line[sepIndex+1:], " ") valueStr := strings.Trim(line[sepIndex+1:], " ")
keyStr := strings.Trim(line[:sepIndex], " ") keyStr := strings.Trim(line[:sepIndex], " ")
switch keyStr { cfg[keyStr] = valueStr
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
}
} }
return cfg return cfg

View File

@ -7,7 +7,7 @@ import (
func TestParseSqlite(t *testing.T) { func TestParseSqlite(t *testing.T) {
cfg := Parse("./testdata/world.mt.sqlite") cfg := Parse("./testdata/world.mt.sqlite")
if cfg.Backend != BACKEND_SQLITE3 { if cfg[CONFIG_BACKEND] != BACKEND_SQLITE3 {
t.Fatal("not sqlite3") t.Fatal("not sqlite3")
} }
} }
@ -15,11 +15,11 @@ func TestParseSqlite(t *testing.T) {
func TestParsePostgres(t *testing.T) { func TestParsePostgres(t *testing.T) {
cfg := Parse("./testdata/world.mt.postgres") cfg := Parse("./testdata/world.mt.postgres")
fmt.Println(cfg) fmt.Println(cfg)
if cfg.Backend != BACKEND_POSTGRES { if cfg[CONFIG_BACKEND] != BACKEND_POSTGRES {
t.Fatal("not 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") t.Fatal("param err")
} }
} }