about summary refs log tree commit diff
path: root/file/file.go
diff options
context:
space:
mode:
Diffstat (limited to 'file/file.go')
-rw-r--r--file/file.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/file/file.go b/file/file.go
new file mode 100644
index 0000000..ce6ac9c
--- /dev/null
+++ b/file/file.go
@@ -0,0 +1,31 @@
+package file
+
+import (
+	"encoding/csv"
+	"git.darknebu.la/bit/logplus"
+	"os"
+)
+
+type File struct {
+	f *os.File
+}
+
+func Open(path string) (File, error) {
+	file, err := os.Open(path)
+	if err != nil {
+		logplus.LogFError("openStarsCSV Panic! (cannot read file from %s)", path)
+	}
+	return File{f: file}, err
+}
+
+func (file *File) ReadCSV() ([][]string, error) {
+	lines, err := csv.NewReader(file.f).ReadAll()
+	if err != nil {
+		logplus.LogError("openStarsCSV Panic! (cannot read the files content)")
+	}
+	return lines, err
+}
+
+func (file *File) Close() error {
+	return file.f.Close()
+}