psql plain worldconfig
This commit is contained in:
parent
fced5f03d2
commit
bac0472282
@ -58,7 +58,7 @@ func Setup(p params.ParamsType, cfg *Config) *App {
|
||||
a.Mapblockrenderer = mapblockrenderer.NewMapBlockRenderer(a.BlockAccessor, a.Colormapping)
|
||||
|
||||
//mapserver database
|
||||
if a.Worldconfig.MapObjectConnection != nil {
|
||||
if a.Worldconfig.MapObjectConnection != "" {
|
||||
//TODO: Psql connection
|
||||
|
||||
} else {
|
||||
|
@ -2,9 +2,7 @@ package worldconfig
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -18,7 +16,6 @@ const (
|
||||
CONFIG_BACKEND string = "backend"
|
||||
CONFIG_PLAYER_BACKEND string = "player_backend"
|
||||
CONFIG_PSQL_CONNECTION string = "pgsql_connection"
|
||||
CONFIG_PSQL_PLAYER_CONNECTION string = "pgsql_player_connection"
|
||||
CONFIG_PSQL_MAPSERVER string = "pgsql_mapserver_connection"
|
||||
)
|
||||
|
||||
@ -34,34 +31,10 @@ type WorldConfig struct {
|
||||
Backend string
|
||||
PlayerBackend string
|
||||
|
||||
PsqlConnection *PsqlConfig
|
||||
PsqlPlayerConnection *PsqlConfig
|
||||
MapObjectConnection *PsqlConfig
|
||||
PsqlConnection string
|
||||
MapObjectConnection string
|
||||
}
|
||||
|
||||
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 {
|
||||
file, err := os.Open(filename)
|
||||
@ -89,11 +62,9 @@ func Parse(filename string) WorldConfig {
|
||||
case CONFIG_PLAYER_BACKEND:
|
||||
cfg.PlayerBackend = valueStr
|
||||
case CONFIG_PSQL_CONNECTION:
|
||||
cfg.PsqlConnection = parseConnectionString(valueStr)
|
||||
case CONFIG_PSQL_PLAYER_CONNECTION:
|
||||
cfg.PsqlPlayerConnection = parseConnectionString(valueStr)
|
||||
cfg.PsqlConnection = valueStr
|
||||
case CONFIG_PSQL_MAPSERVER:
|
||||
cfg.MapObjectConnection = parseConnectionString(valueStr)
|
||||
cfg.MapObjectConnection = valueStr
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,9 +10,6 @@ func TestParseSqlite(t *testing.T) {
|
||||
if cfg.Backend != BACKEND_SQLITE3 {
|
||||
t.Fatal("not sqlite3")
|
||||
}
|
||||
if cfg.PlayerBackend != BACKEND_FILES {
|
||||
t.Fatal("not files")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePostgres(t *testing.T) {
|
||||
@ -22,15 +19,7 @@ func TestParsePostgres(t *testing.T) {
|
||||
t.Fatal("not postgres")
|
||||
}
|
||||
|
||||
if cfg.PlayerBackend != BACKEND_POSTGRES {
|
||||
t.Fatal("not postgres")
|
||||
}
|
||||
|
||||
if cfg.PsqlConnection.Host != "postgres" {
|
||||
if cfg.PsqlConnection != "host=postgres port=5432 user=postgres password=enter dbname=postgres" {
|
||||
t.Fatal("param err")
|
||||
}
|
||||
|
||||
if cfg.PsqlConnection.Port != 5432 {
|
||||
t.Fatal("param err: ", cfg.PsqlConnection.Port)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user