add example, cleanup docs
diff --git a/example_test.go b/example_test.go
index 480df84..0cf5b72 100644
--- a/example_test.go
+++ b/example_test.go
@@ -61,3 +61,21 @@
fmt.Printf("%s %s\n", cfg.Profile["A"].Color, cfg.Profile["B"].Color)
// Output: white black
}
+
+func ExampleReadStringInto_multivalue() {
+ cfgStr := `; Comment line
+[section]
+multi=value1
+multi=value2`
+ cfg := struct {
+ Section struct {
+ Multi []string
+ }
+ }{}
+ err := gcfg.ReadStringInto(&cfg, cfgStr)
+ if err != nil {
+ log.Fatalf("Failed to parse gcfg data: %s", err)
+ }
+ fmt.Println(cfg.Section.Multi)
+ // Output: [value1 value2]
+}
diff --git a/gcfg.go b/gcfg.go
index c5fe554..fbaf5cc 100644
--- a/gcfg.go
+++ b/gcfg.go
@@ -46,6 +46,10 @@
// without a subsection name, its values are stored with the empty string used
// as the key.
//
+// The functions in this package panic if config is not a pointer to a struct,
+// or when a field is not of a suitable type (either a struct or a map with
+// string keys and pointer-to-struct values).
+//
// Parsing of values
//
// The section structs in the config struct may contain arbitrary types.
diff --git a/read.go b/read.go
index b5ccae4..01bc139 100644
--- a/read.go
+++ b/read.go
@@ -148,15 +148,6 @@
// ReadInto reads gcfg formatted data from reader and sets the values into the
// corresponding fields in config.
-// Config must be a pointer to a struct conforming to the rules described in
-// "Data structure" above.
-//
-// ReadInto panics if config is not a pointer to a struct, or if it encounters a
-// field that is not of a suitable type (either a struct or a map with string
-// keys and pointer-to-struct values).
-//
-// See ReadStringInto for examples.
-//
func ReadInto(config interface{}, reader io.Reader) error {
src, err := ioutil.ReadAll(reader)
if err != nil {
@@ -169,8 +160,6 @@
// ReadStringInto reads gcfg formatted data from str and sets the values into
// the corresponding fields in config.
-// ReadStringInfo is a wrapper for ReadInfo; see ReadInto(config, reader) for
-// detailed description of how data is read and set into config.
func ReadStringInto(config interface{}, str string) error {
r := strings.NewReader(str)
return ReadInto(config, r)
@@ -178,8 +167,6 @@
// ReadFileInto reads gcfg formatted data from the file filename and sets the
// values into the corresponding fields in config.
-// ReadFileInto is a wrapper for ReadInfo; see ReadInto(config, reader) for
-// detailed description of how data is read and set into config.
func ReadFileInto(config interface{}, filename string) error {
f, err := os.Open(filename)
if err != nil {