Publicize the raw io.Reader reading function
This commit is contained in:
parent
863e415310
commit
3cfe8be7bb
@ -116,12 +116,7 @@ type Config struct {
|
||||
|
||||
// Load loads and parses the files /etc/xdg/<name>/<name>.conf and
|
||||
// <home>/.config/<name>/<name>.conf, unless the corresponding XDG environment
|
||||
// variables are set - then it uses those. Configuration files are divided into
|
||||
// lines where each line may be blank, a comment, or a key-value pair. If the
|
||||
// line is blank or begins with a # character, it is ignored. Else, the line
|
||||
// must have a key and a value separated by a colon. Before they are processed,
|
||||
// leading and trailing whitespace is trimmed from the key and the value. Keys
|
||||
// are case sensitive.
|
||||
// variables are set - then it uses those.
|
||||
func (config *Config) Load (name string) (err error) {
|
||||
if strings.ContainsAny(name, "/\\|:.%") {
|
||||
err = ErrorIllegalName
|
||||
@ -158,7 +153,7 @@ func (config *Config) Load (name string) (err error) {
|
||||
|
||||
file, fileErr := os.Open(path)
|
||||
if fileErr != nil { continue }
|
||||
parseErr := config.loadFile(file)
|
||||
parseErr := config.LoadFrom(file)
|
||||
defer file.Close()
|
||||
|
||||
if parseErr != nil {
|
||||
@ -171,8 +166,14 @@ func (config *Config) Load (name string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (config *Config) loadFile (file io.Reader) (err error) {
|
||||
scanner := bufio.NewScanner(file)
|
||||
// LoadFrom parses a configuration file from an io.Reader. Configuration files
|
||||
// are divided into lines where each line may be blank, a comment, or a
|
||||
// key-value pair. If the line is blank or begins with a # character, it is
|
||||
// ignored. Else, the line must have a key and a value separated by a colon.
|
||||
// Before they are processed, leading and trailing whitespace is trimmed from
|
||||
// the key and the value. Keys are case sensitive.
|
||||
func (config *Config) LoadFrom (reader io.Reader) (err error) {
|
||||
scanner := bufio.NewScanner(reader)
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user