aboutsummaryrefslogtreecommitdiffstats
path: root/file_store.go
diff options
context:
space:
mode:
Diffstat (limited to 'file_store.go')
-rw-r--r--file_store.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/file_store.go b/file_store.go
new file mode 100644
index 0000000..03704f9
--- /dev/null
+++ b/file_store.go
@@ -0,0 +1,29 @@
+package todolist
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+)
+
+type FileStore struct {
+ FileLocation string
+ Data []Todo
+}
+
+func NewFileStore() *FileStore {
+ return &FileStore{FileLocation: "todos.json"}
+}
+
+func (f *FileStore) Load() {
+ data, err := ioutil.ReadFile(f.FileLocation)
+ if err != nil {
+ fmt.Println("Error reading file", err)
+ }
+
+ jerr := json.Unmarshal(data, &f.Data)
+ if jerr != nil {
+ fmt.Println("Error reading json data", jerr)
+ }
+
+}