aboutsummaryrefslogtreecommitdiffstats
path: root/file_store.go
diff options
context:
space:
mode:
Diffstat (limited to 'file_store.go')
-rw-r--r--file_store.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/file_store.go b/file_store.go
index 03704f9..3f71ba2 100644
--- a/file_store.go
+++ b/file_store.go
@@ -4,6 +4,8 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
+ "os"
+ "os/user"
)
type FileStore struct {
@@ -12,18 +14,21 @@ type FileStore struct {
}
func NewFileStore() *FileStore {
- return &FileStore{FileLocation: "todos.json"}
+ usr, _ := user.Current()
+ return &FileStore{FileLocation: usr.HomeDir + "/.todos.json"}
}
func (f *FileStore) Load() {
data, err := ioutil.ReadFile(f.FileLocation)
if err != nil {
fmt.Println("Error reading file", err)
+ os.Exit(1)
}
jerr := json.Unmarshal(data, &f.Data)
if jerr != nil {
fmt.Println("Error reading json data", jerr)
+ os.Exit(1)
}
}