1
0
forked from MTSR/mapserver

parse test

This commit is contained in:
Thomas Rudin 2019-01-04 15:02:25 +01:00
parent 7863099925
commit 9fea93e73a
2 changed files with 28 additions and 0 deletions

View File

@ -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() != "=" {

View File

@ -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")
}
}