Skip to content

Commit

Permalink
Update to support unit32 (#25)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
edfungus authored Jul 17, 2023
1 parent 4b40f22 commit 1e4d858
Showing 1 changed file with 45 additions and 27 deletions.
72 changes: 45 additions & 27 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ import (

// LoadFromReader - Load csv from an io.Reader and put it in a array of the destination's type using tags.
// Example:
// tabOfMyStruct := []MyStruct{}
// err := Load(
// myIoReader,
// &tabOfMyStruct,
// CsvOptions{
// Separator: ';',
// Header: []string{"header1", "header2", "header3"
// }
// })
//
// tabOfMyStruct := []MyStruct{}
// err := Load(
// myIoReader,
// &tabOfMyStruct,
// CsvOptions{
// Separator: ';',
// Header: []string{"header1", "header2", "header3"
// }
// })
//
// @param file: the io.Reader.
// @param destination: object where to store the result.
// @param options (optional): options for the csv parsing.
Expand Down Expand Up @@ -55,15 +57,17 @@ func LoadFromReader(file io.Reader, destination interface{}, options ...CsvOptio

// LoadFromPath - Load csv from a path and put it in a array of the destination's type using tags.
// Example:
// tabOfMyStruct := []MyStruct{}
// err := Load(
// "my_csv_file.csv",
// &tabOfMyStruct,
// CsvOptions{
// Separator: ';',
// Header: []string{"header1", "header2", "header3"
// }
// })
//
// tabOfMyStruct := []MyStruct{}
// err := Load(
// "my_csv_file.csv",
// &tabOfMyStruct,
// CsvOptions{
// Separator: ';',
// Header: []string{"header1", "header2", "header3"
// }
// })
//
// @param path: the path of the csv file.
// @param destination: object where to store the result.
// @param options (optional): options for the csv parsing.
Expand All @@ -85,15 +89,17 @@ func LoadFromPath(path string, destination interface{}, options ...CsvOptions) e

// LoadFromString - Load csv from string and put it in a array of the destination's type using tags.
// Example:
// tabOfMyStruct := []MyStruct{}
// err := Load(
// myString,
// &tabOfMyStruct,
// CsvOptions{
// Separator: ';',
// Header: []string{"header1", "header2", "header3"
// }
// })
//
// tabOfMyStruct := []MyStruct{}
// err := Load(
// myString,
// &tabOfMyStruct,
// CsvOptions{
// Separator: ';',
// Header: []string{"header1", "header2", "header3"
// }
// })
//
// @param str: the string.
// @param destination: object where to store the result.
// @param options (optional): options for the csv parsing.
Expand Down Expand Up @@ -196,6 +202,18 @@ func storeValue(rawValue string, valRv reflect.Value) error {
switch valRv.Kind() {
case reflect.String:
valRv.SetString(rawValue)
case reflect.Uint32:
fallthrough
case reflect.Uint64:
fallthrough
case reflect.Uint:
value, err := strconv.ParseUint(rawValue, 10, 64)
if err != nil && rawValue != "" {
return fmt.Errorf("error parsing uint '%v':\n ==> %v", rawValue, err)
}
valRv.SetUint(value)
case reflect.Int32:
fallthrough
case reflect.Int64:
fallthrough
case reflect.Int:
Expand Down

0 comments on commit 1e4d858

Please sign in to comment.