Skip to content

Commit 82d996c

Browse files
authored
Fix typos (#31)
1 parent 2f2b4b6 commit 82d996c

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

.github/workflows/go.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,17 @@ jobs:
1414
steps:
1515

1616
- name: Set up Go 1.x
17-
uses: actions/setup-go@v2
17+
uses: actions/setup-go@v5
1818
with:
19-
go-version: ^1.13
20-
id: go
19+
go-version: ^1.24
20+
cache: true
2121

2222
- name: Check out code into the Go module directory
23-
uses: actions/checkout@v2
23+
uses: actions/checkout@v4
2424

2525
- name: Get dependencies
2626
run: |
27-
go get -v -t -d ./...
28-
if [ -f Gopkg.toml ]; then
29-
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
30-
dep ensure
31-
fi
27+
go mod download
3228
3329
- name: Build
3430
run: go build -v .

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
.glide/
1515

1616
csv_files/csv_file_name.csv
17+
.idea/

dump.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
// @param slice: an object typically of the form []struct, where the struct is using csv tags.
1616
// @param writer: the location of where you will write the slice content to. Example: File, Stdout, etc.
1717
// @param options (optional): options for the csv parsing.
18-
// @return an error if one occures.
19-
func DumpToWriter(slice interface{}, writer io.Writer, options ...CsvOptions) error {
18+
// @return an error if one occurs.
19+
func DumpToWriter(slice any, writer io.Writer, options ...CsvOptions) error {
2020
// If slice is a pointer, get the value it points to.
2121
// (if it isn't, Indirect() does nothing and returns the value it was called with).
2222
reflectedValue := reflect.Indirect(reflect.ValueOf(slice))
@@ -58,10 +58,10 @@ func DumpToWriter(slice interface{}, writer io.Writer, options ...CsvOptions) er
5858
return err
5959
}
6060

61-
for i := 0; i < reflectedValue.Len(); i++ {
62-
line := []string{}
61+
for i := range reflectedValue.Len() {
62+
var line []string
6363

64-
for j := 0; j < reflectedValue.Type().Elem().NumField(); j++ {
64+
for j := range reflectedValue.Type().Elem().NumField() {
6565
valueRv := reflectedValue.Index(i)
6666
value := valueRv.Field(j)
6767
tag := valueRv.Type().Field(j).Tag.Get(option.TagKey)
@@ -91,8 +91,8 @@ func DumpToWriter(slice interface{}, writer io.Writer, options ...CsvOptions) er
9191
// @param slice: An object typically of the form []struct, where the struct is using csv tag.
9292
// @param path: The file path string of where you want the file to be created.
9393
// @param options (optional): options for the csv parsing.
94-
// @return an error if one occures.
95-
func DumpToFile(slice interface{}, path string, options ...CsvOptions) error {
94+
// @return an error if one occurs.
95+
func DumpToFile(slice any, path string, options ...CsvOptions) error {
9696
file, err := os.Create(path)
9797
if err != nil {
9898
return err
@@ -108,8 +108,8 @@ func DumpToFile(slice interface{}, path string, options ...CsvOptions) error {
108108
// DumpToString - writes a slice content into a string.
109109
// @param slice: An object typically of the form []struct, where the struct is using csv tag.
110110
// @param options (optional): options for the csv parsing.
111-
// @return a string and an error if one occures.
112-
func DumpToString(slice interface{}, options ...CsvOptions) (string, error) {
111+
// @return a string and an error if one occurs.
112+
func DumpToString(slice any, options ...CsvOptions) (string, error) {
113113

114114
writer := new(bytes.Buffer)
115115

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/artonge/go-csv-tag/v2
22

3-
go 1.12
3+
go 1.24

load.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ func LoadFromReader(file io.Reader, destination interface{}, options ...CsvOptio
7979
// @return an error if one occurs.
8080
func LoadFromPath(path string, destination interface{}, options ...CsvOptions) error {
8181
file, err := os.Open(path)
82-
defer file.Close()
8382
if err != nil {
8483
return err
8584
}
86-
85+
defer file.Close()
8786
err = LoadFromReader(file, destination, options...)
8887
if err != nil {
8988
return fmt.Errorf("error mapping csv from path %v:\n ==> %v", path, err)
@@ -261,6 +260,8 @@ func storeValue(rawValue string, valRv reflect.Value) error {
261260
return fmt.Errorf("error parsing bool '%v':\n ==> %v", rawValue, err)
262261
}
263262
valRv.SetBool(value)
263+
default:
264+
return fmt.Errorf("unsupported type '%v' for value '%v'", valRv.Kind(), rawValue)
264265
}
265266

266267
return nil

0 commit comments

Comments
 (0)