1
0
forked from MTSR/mapserver
mapserver/worldconfig/parse.go

47 lines
867 B
Go
Raw Permalink Normal View History

2019-01-04 15:02:17 +03:00
package worldconfig
import (
"bufio"
"os"
2019-01-13 18:37:03 +03:00
"strings"
2019-01-04 15:02:17 +03:00
)
const (
2019-01-13 18:37:03 +03:00
BACKEND_SQLITE3 string = "sqlite3"
BACKEND_FILES string = "files"
2019-01-04 15:02:17 +03:00
BACKEND_POSTGRES string = "postgresql"
)
const (
2019-02-07 10:02:13 +03:00
CONFIG_BACKEND string = "backend"
CONFIG_PLAYER_BACKEND string = "player_backend"
CONFIG_PSQL_CONNECTION string = "pgsql_connection"
CONFIG_PSQL_MAPSERVER string = "pgsql_mapserver_connection"
2019-01-04 15:02:17 +03:00
)
2019-01-04 12:44:41 +03:00
2019-02-08 16:57:36 +03:00
func Parse(filename string) map[string]string {
2019-01-04 15:02:17 +03:00
file, err := os.Open(filename)
if err != nil {
panic(err)
}
defer file.Close()
2019-02-08 16:57:36 +03:00
cfg := make(map[string]string)
2019-01-04 17:02:25 +03:00
2019-01-04 15:02:17 +03:00
scanner := bufio.NewScanner(file)
for scanner.Scan() {
2019-01-05 19:21:24 +03:00
line := scanner.Text()
sepIndex := strings.Index(line, "=")
if sepIndex < 0 {
continue
2019-01-04 15:02:17 +03:00
}
2019-01-05 19:21:24 +03:00
valueStr := strings.Trim(line[sepIndex+1:], " ")
keyStr := strings.Trim(line[:sepIndex], " ")
2019-02-08 16:57:36 +03:00
cfg[keyStr] = valueStr
2019-01-04 15:02:17 +03:00
}
2019-01-04 13:00:49 +03:00
2019-01-04 15:02:17 +03:00
return cfg
2019-01-04 13:00:49 +03:00
}