feat: add ReadCsvFile

This commit is contained in:
dudaodong committed 2023-04-25 11:28:43 +08:00
1 parent 11217a11c7
commit 2f51397d2c
3 files changed
+44 -1

No files matched your search

+19
View File
@@ -11,6 +11,7 @@ import (
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"encoding/csv"
"errors"
"fmt"
"io"
@@ -434,3 +435,21 @@ func Sha(filepath string, shaType ...int) (string, error) {
return sha, nil
}
// MTime returns file modified time.
// Play: todo
func ReadCsvFile(filepath string) ([][]string, error) {
f, err := os.Open(filepath)
if err != nil {
return nil, err
}
defer f.Close()
csvReader := csv.NewReader(f)
records, err := csvReader.ReadAll()
if err != nil {
return nil, err
}
return records, nil
}