psql plain worldconfig

This commit is contained in:
NatureFreshMilk 2019-02-06 15:52:34 +01:00
parent fced5f03d2
commit bac0472282
3 changed files with 6 additions and 46 deletions

View File

@ -58,7 +58,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 != nil { if a.Worldconfig.MapObjectConnection != "" {
//TODO: Psql connection //TODO: Psql connection
} else { } else {

View File

@ -2,9 +2,7 @@ package worldconfig
import ( import (
"bufio" "bufio"
"fmt"
"os" "os"
"strconv"
"strings" "strings"
) )
@ -18,7 +16,6 @@ const (
CONFIG_BACKEND string = "backend" CONFIG_BACKEND string = "backend"
CONFIG_PLAYER_BACKEND string = "player_backend" CONFIG_PLAYER_BACKEND string = "player_backend"
CONFIG_PSQL_CONNECTION string = "pgsql_connection" CONFIG_PSQL_CONNECTION string = "pgsql_connection"
CONFIG_PSQL_PLAYER_CONNECTION string = "pgsql_player_connection"
CONFIG_PSQL_MAPSERVER string = "pgsql_mapserver_connection" CONFIG_PSQL_MAPSERVER string = "pgsql_mapserver_connection"
) )
@ -34,34 +31,10 @@ type WorldConfig struct {
Backend string Backend string
PlayerBackend string PlayerBackend string
PsqlConnection *PsqlConfig PsqlConnection string
PsqlPlayerConnection *PsqlConfig MapObjectConnection string
MapObjectConnection *PsqlConfig
} }
func parseConnectionString(str string) *PsqlConfig {
cfg := PsqlConfig{}
pairs := strings.Split(str, " ")
for _, pair := range pairs {
fmt.Println(pair)
kv := strings.Split(pair, "=")
switch kv[0] {
case "host":
cfg.Host = kv[1]
case "port":
cfg.Port, _ = strconv.Atoi(kv[1])
case "user":
cfg.Host = kv[1]
case "password":
cfg.Password = kv[1]
case "dbname":
cfg.DbName = kv[1]
}
}
return &cfg
}
func Parse(filename string) WorldConfig { func Parse(filename string) WorldConfig {
file, err := os.Open(filename) file, err := os.Open(filename)
@ -89,11 +62,9 @@ func Parse(filename string) WorldConfig {
case CONFIG_PLAYER_BACKEND: case CONFIG_PLAYER_BACKEND:
cfg.PlayerBackend = valueStr cfg.PlayerBackend = valueStr
case CONFIG_PSQL_CONNECTION: case CONFIG_PSQL_CONNECTION:
cfg.PsqlConnection = parseConnectionString(valueStr) cfg.PsqlConnection = valueStr
case CONFIG_PSQL_PLAYER_CONNECTION:
cfg.PsqlPlayerConnection = parseConnectionString(valueStr)
case CONFIG_PSQL_MAPSERVER: case CONFIG_PSQL_MAPSERVER:
cfg.MapObjectConnection = parseConnectionString(valueStr) cfg.MapObjectConnection = valueStr
} }
} }

View File

@ -10,9 +10,6 @@ func TestParseSqlite(t *testing.T) {
if cfg.Backend != BACKEND_SQLITE3 { if cfg.Backend != BACKEND_SQLITE3 {
t.Fatal("not sqlite3") t.Fatal("not sqlite3")
} }
if cfg.PlayerBackend != BACKEND_FILES {
t.Fatal("not files")
}
} }
func TestParsePostgres(t *testing.T) { func TestParsePostgres(t *testing.T) {
@ -22,15 +19,7 @@ func TestParsePostgres(t *testing.T) {
t.Fatal("not postgres") t.Fatal("not postgres")
} }
if cfg.PlayerBackend != BACKEND_POSTGRES { if cfg.PsqlConnection != "host=postgres port=5432 user=postgres password=enter dbname=postgres" {
t.Fatal("not postgres")
}
if cfg.PsqlConnection.Host != "postgres" {
t.Fatal("param err") t.Fatal("param err")
} }
if cfg.PsqlConnection.Port != 5432 {
t.Fatal("param err: ", cfg.PsqlConnection.Port)
}
} }