From af8b1814aa3f5a63e913923449b29cac748fba57 Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Sun, 24 Apr 2016 09:55:07 -0400 Subject: WIP on getting stores implemented --- file_store.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 file_store.go (limited to 'file_store.go') 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) + } + +} -- cgit v1.3