From 0525bc463f53487a7de8409697fabec28471a0bd Mon Sep 17 00:00:00 2001 From: emile Date: Mon, 15 Oct 2018 16:07:22 +0200 Subject: for detailed information about the changes, see https://git.darknebu.la/GalaxySimulator/Source/pulls/1 --- file/file.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 file/file.go (limited to 'file') 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() +} -- cgit 1.4.1