diff options
author | Matthew Lemon <y@yulqen.org> | 2024-04-20 16:42:06 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-04-20 16:42:06 +0100 |
commit | ed8a51dd320c5fb003f12003c7a66cfa353f6f81 (patch) | |
tree | d7a41ac466c53defaf7dd19364013432f366c666 /cmd/dbasik-api/return.go | |
parent | 04f78ef7a46ae4c4b8ab49153c16983c590783f5 (diff) |
wip: testing the file package interface
Diffstat (limited to 'cmd/dbasik-api/return.go')
-rw-r--r-- | cmd/dbasik-api/return.go | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/cmd/dbasik-api/return.go b/cmd/dbasik-api/return.go index 294c960..0973fc9 100644 --- a/cmd/dbasik-api/return.go +++ b/cmd/dbasik-api/return.go @@ -58,20 +58,6 @@ func NewReturn(name string, dm *Datamap, returnLines []ReturnLine) (*Return, err }, nil } -//func cellVisitor(c *xlsx.Cell) error { -// value, err := c.FormattedValue() -// if err != nil { -// fmt.Println(err.Error()) -// } else { -// fmt.Printf("Sheet: %s, Cell value: %s\n", c.Row.Sheet.Name, value) -// } -// return err -//} - -//func rowVisitor(r *xlsx.Row) error { -// return r.ForEachCell(cellVisitor, xlsx.SkipEmptyCells) -//} - func ParseXLSX(filePath string, dm *Datamap) (*Return, error) { // Use tealeg/xlsx to parse the Excel file wb, err := xlsx.OpenFile(filePath) @@ -128,3 +114,25 @@ func contains(slice []string, str string) bool { } return false } + +type FilePreparer interface { + Prepare(filePath string) error +} + +type DirectoryFilePackage struct { + FilePath string +} + +func (fp *DirectoryFilePackage) Prepare() ([]string, error) { + // return a slice of the files inside the directory pointed to by fh.FilePath + // and an error if any + files, err := filepath.Glob(fp.FilePath + "/*") + if err != nil { + return nil, err + } + return files, nil +} + +func NewDirectoryFilePackage(filePath string) *DirectoryFilePackage { + return &DirectoryFilePackage{FilePath: filePath} +} |