43 lines
555 B
Go
43 lines
555 B
Go
|
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
|
||
|
}
|