]> Cypherpunks.ru repositories - gorecfile.git/commitdiff
Add NextMapWithSlice v0.4.0
authorSergey Matveev <stargrave@stargrave.org>
Tue, 29 Dec 2020 13:56:48 +0000 (16:56 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 29 Dec 2020 13:56:48 +0000 (16:56 +0300)
r.go

diff --git a/r.go b/r.go
index ca9bba8316c63b248bcc2eacb648e50db564f427..71400f0f9a23eff4e6d1796a2ba1ad3683e827f3 100644 (file)
--- a/r.go
+++ b/r.go
@@ -124,7 +124,7 @@ func (r *Reader) Next() ([]Field, error) {
        return fields, nil
 }
 
-// Same as Next(), but creates map from the fields.
+// Same as Next(), but with unique keys and last value.
 func (r *Reader) NextMap() (map[string]string, error) {
        fields, err := r.Next()
        if err != nil {
@@ -136,3 +136,16 @@ func (r *Reader) NextMap() (map[string]string, error) {
        }
        return m, nil
 }
+
+// Same as Next(), but with unique keys and slices of values.
+func (r *Reader) NextMapWithSlice() (map[string][]string, error) {
+       fields, err := r.Next()
+       if err != nil {
+               return nil, err
+       }
+       m := make(map[string][]string)
+       for _, f := range fields {
+               m[f.Name] = append(m[f.Name], f.Value)
+       }
+       return m, nil
+}