Skip to content

Commit 1e4d858

Browse files
authored
Update to support unit32 (#25)
* Update to support unit32 After this update artonge/go-gtfs#22, the sequence always returned 0 because this library didn't support uint32. This should fix the issue. Tested with the go-gtfs library with this change. * updated to fallthrough and added uint64 * Added unint and int32 as well
1 parent 4b40f22 commit 1e4d858

File tree

1 file changed

+45
-27
lines changed

1 file changed

+45
-27
lines changed

load.go

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ import (
1212

1313
// LoadFromReader - Load csv from an io.Reader and put it in a array of the destination's type using tags.
1414
// Example:
15-
// tabOfMyStruct := []MyStruct{}
16-
// err := Load(
17-
// myIoReader,
18-
// &tabOfMyStruct,
19-
// CsvOptions{
20-
// Separator: ';',
21-
// Header: []string{"header1", "header2", "header3"
22-
// }
23-
// })
15+
//
16+
// tabOfMyStruct := []MyStruct{}
17+
// err := Load(
18+
// myIoReader,
19+
// &tabOfMyStruct,
20+
// CsvOptions{
21+
// Separator: ';',
22+
// Header: []string{"header1", "header2", "header3"
23+
// }
24+
// })
25+
//
2426
// @param file: the io.Reader.
2527
// @param destination: object where to store the result.
2628
// @param options (optional): options for the csv parsing.
@@ -55,15 +57,17 @@ func LoadFromReader(file io.Reader, destination interface{}, options ...CsvOptio
5557

5658
// LoadFromPath - Load csv from a path and put it in a array of the destination's type using tags.
5759
// Example:
58-
// tabOfMyStruct := []MyStruct{}
59-
// err := Load(
60-
// "my_csv_file.csv",
61-
// &tabOfMyStruct,
62-
// CsvOptions{
63-
// Separator: ';',
64-
// Header: []string{"header1", "header2", "header3"
65-
// }
66-
// })
60+
//
61+
// tabOfMyStruct := []MyStruct{}
62+
// err := Load(
63+
// "my_csv_file.csv",
64+
// &tabOfMyStruct,
65+
// CsvOptions{
66+
// Separator: ';',
67+
// Header: []string{"header1", "header2", "header3"
68+
// }
69+
// })
70+
//
6771
// @param path: the path of the csv file.
6872
// @param destination: object where to store the result.
6973
// @param options (optional): options for the csv parsing.
@@ -85,15 +89,17 @@ func LoadFromPath(path string, destination interface{}, options ...CsvOptions) e
8589

8690
// LoadFromString - Load csv from string and put it in a array of the destination's type using tags.
8791
// Example:
88-
// tabOfMyStruct := []MyStruct{}
89-
// err := Load(
90-
// myString,
91-
// &tabOfMyStruct,
92-
// CsvOptions{
93-
// Separator: ';',
94-
// Header: []string{"header1", "header2", "header3"
95-
// }
96-
// })
92+
//
93+
// tabOfMyStruct := []MyStruct{}
94+
// err := Load(
95+
// myString,
96+
// &tabOfMyStruct,
97+
// CsvOptions{
98+
// Separator: ';',
99+
// Header: []string{"header1", "header2", "header3"
100+
// }
101+
// })
102+
//
97103
// @param str: the string.
98104
// @param destination: object where to store the result.
99105
// @param options (optional): options for the csv parsing.
@@ -196,6 +202,18 @@ func storeValue(rawValue string, valRv reflect.Value) error {
196202
switch valRv.Kind() {
197203
case reflect.String:
198204
valRv.SetString(rawValue)
205+
case reflect.Uint32:
206+
fallthrough
207+
case reflect.Uint64:
208+
fallthrough
209+
case reflect.Uint:
210+
value, err := strconv.ParseUint(rawValue, 10, 64)
211+
if err != nil && rawValue != "" {
212+
return fmt.Errorf("error parsing uint '%v':\n ==> %v", rawValue, err)
213+
}
214+
valRv.SetUint(value)
215+
case reflect.Int32:
216+
fallthrough
199217
case reflect.Int64:
200218
fallthrough
201219
case reflect.Int:

0 commit comments

Comments
 (0)