about summary refs log tree commit diff
path: root/file/file.go
blob: ce6ac9c5a4619dc80560b24ddee5de1d9758cf34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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()
}