about summary refs log tree commit diff
path: root/file
diff options
context:
space:
mode:
authoremile <hanemile@protonmail.com>2018-10-15 16:07:22 +0200
committeremile <hanemile@protonmail.com>2018-10-15 16:07:22 +0200
commit0525bc463f53487a7de8409697fabec28471a0bd (patch)
tree5cad6a659bdfc471e0865797bf1e19fbf8f81f02 /file
parent088372b31882dd0217d8cc36d7abeac8b6268382 (diff)
for detailed information about the changes, see https://git.darknebu.la/GalaxySimulator/Source/pulls/1
Diffstat (limited to 'file')
-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()
+}