Skip to content

Instantly share code, notes, and snippets.

@trygveaa
Last active August 29, 2015 14:01
Show Gist options
  • Save trygveaa/55a172404598813297bf to your computer and use it in GitHub Desktop.
Save trygveaa/55a172404598813297bf to your computer and use it in GitHub Desktop.
A simple config parser for go
// Moved to https://github.com/itkinside/itkconfig
@hermansc
Copy link

hermansc commented May 6, 2014

Line 65-68, is perhaps better written like below in order to support setting booleans with 1 and 0's as well.

v, err := strings.ParseBool(value)
if err != nil {
    return config, fmt.Errorf("Invalid bool...")
}
field.SetBool(v)

I also think it is better to use bufio and the os package in order to read lines. So something like:

f, _ := os.Open(filename)
fh, _ := bufio.NewScanner(f)
for fh.Scan() {
    line := strings.TrimSpace(fh.Text())
}

And lastly, what is "Nr" meant to represent in the config?

@trygveaa
Copy link
Author

trygveaa commented May 6, 2014

Thanks, and agreed. I have applied your suggestions.

"Nr" is just an example field of type int.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment