residentsleeper/config.go

43 lines
555 B
Go
Raw Normal View History

2019-04-17 01:42:46 +00:00
package main
import (
"bufio"
"os"
"strings"
)
func loadServerConfig(configPath string) (map[string]string, error) {
f, err := os.Open(configPath)
if err != nil {
return nil, err
}
defer f.Close()
scanner := bufio.NewScanner(f)
var text string
var m []string
ret := make(map[string]string)
for scanner.Scan() {
text = scanner.Text()
if text[0] == '#' {
continue
}
m = configRegexp.FindStringSubmatch(text)
if m == nil {
continue
}
ret[strings.TrimSpace(m[1])] = strings.TrimSpace(m[2])
}
return ret, nil
}