From 8d399fb056d1c497a3e3d41fd5f33d2a6e2948ab Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Fri, 4 Jan 2019 16:10:21 +0100 Subject: [PATCH] use type --- worldconfig/parse.go | 17 ++++++++++++----- worldconfig/parse_test.go | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/worldconfig/parse.go b/worldconfig/parse.go index e641477..f7bb74b 100644 --- a/worldconfig/parse.go +++ b/worldconfig/parse.go @@ -19,16 +19,24 @@ const ( CONFIG_PSQL_PLAYER_CONNECTION string = "pgsql_player_connection" ) +type PsqlConfig struct { + Host string + Port int + Username string + Password string + DbName string +} + type WorldConfig struct { Backend string PlayerBackend string - PsqlConnection map[string]string - PsqlPlayerConnection map[string]string + PsqlConnection *PsqlConfig + PsqlPlayerConnection *PsqlConfig } -func parseConnectionString(str string) map[string]string { - return make(map[string]string) +func parseConnectionString(str string) *PsqlConfig { + return &PsqlConfig{} } func Parse(filename string) WorldConfig { @@ -39,7 +47,6 @@ func Parse(filename string) WorldConfig { defer file.Close() cfg := WorldConfig{} - cfg.PsqlConnection = parseConnectionString("") scanner := bufio.NewScanner(file) for scanner.Scan() { diff --git a/worldconfig/parse_test.go b/worldconfig/parse_test.go index da018ca..e18d897 100644 --- a/worldconfig/parse_test.go +++ b/worldconfig/parse_test.go @@ -33,7 +33,7 @@ func TestParsePostgres(t *testing.T) { t.Fatal("no connection") } - if cfg.PsqlConnection[""] != "x" { + if cfg.PsqlConnection.Host != "postgres" { t.Fatal("param err") } }