33 lines
680 B
Go
33 lines
680 B
Go
package config
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// parseFile opens the file at the given filename path, then treat each line
|
|
// not starting with '#' as a configuration statement.
|
|
func parseFile(o *Config, filename string) error {
|
|
fp, err := os.Open(filename)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer fp.Close()
|
|
|
|
scanner := bufio.NewScanner(fp)
|
|
n := 0
|
|
for scanner.Scan() {
|
|
n += 1
|
|
line := strings.TrimSpace(scanner.Text())
|
|
if len(line) > 0 && !strings.HasPrefix(line, "#") && strings.Index(line, "=") > 0 {
|
|
err := parseLine(o, line)
|
|
if err != nil {
|
|
return fmt.Errorf("%v:%d: error in configuration: %w", filename, n, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|