1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-12 16:52:29 +08:00

feat: add ReadCsvFile

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

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
}