From 9fea93e73a7261b3dc4cb9d4eca91f73fd4f7829 Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Fri, 4 Jan 2019 15:02:25 +0100 Subject: [PATCH] parse test --- worldconfig/parse.go | 15 +++++++++++++++ worldconfig/parse_test.go | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/worldconfig/parse.go b/worldconfig/parse.go index 4dcdd92..e641477 100644 --- a/worldconfig/parse.go +++ b/worldconfig/parse.go @@ -15,11 +15,20 @@ const ( 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" ) type WorldConfig struct { Backend string PlayerBackend string + + PsqlConnection map[string]string + PsqlPlayerConnection map[string]string +} + +func parseConnectionString(str string) map[string]string { + return make(map[string]string) } func Parse(filename string) WorldConfig { @@ -30,6 +39,8 @@ func Parse(filename string) WorldConfig { defer file.Close() cfg := WorldConfig{} + cfg.PsqlConnection = parseConnectionString("") + scanner := bufio.NewScanner(file) for scanner.Scan() { sc := bufio.NewScanner(strings.NewReader(scanner.Text())) @@ -41,6 +52,10 @@ func Parse(filename string) WorldConfig { cfg.Backend = sc.Text() case CONFIG_PLAYER_BACKEND: cfg.PlayerBackend = sc.Text() + case CONFIG_PSQL_CONNECTION: + cfg.PsqlConnection = parseConnectionString(sc.Text()) + case CONFIG_PSQL_PLAYER_CONNECTION: + cfg.PsqlPlayerConnection = parseConnectionString(sc.Text()) } if sc.Text() != "=" { diff --git a/worldconfig/parse_test.go b/worldconfig/parse_test.go index d365d96..da018ca 100644 --- a/worldconfig/parse_test.go +++ b/worldconfig/parse_test.go @@ -20,7 +20,20 @@ func TestParsePostgres(t *testing.T) { if cfg.Backend != worldconfig.BACKEND_POSTGRES { t.Fatal("not postgres") } + if cfg.PlayerBackend != worldconfig.BACKEND_POSTGRES { t.Fatal("not postgres") } + + if cfg.PsqlConnection == nil { + t.Fatal("no connection") + } + + if cfg.PsqlPlayerConnection == nil { + t.Fatal("no connection") + } + + if cfg.PsqlConnection[""] != "x" { + t.Fatal("param err") + } }