diff options
| author | Grant Ammons <gammons@gmail.com> | 2016-04-24 09:55:07 -0400 |
|---|---|---|
| committer | Grant Ammons <gammons@gmail.com> | 2016-04-24 09:55:07 -0400 |
| commit | af8b1814aa3f5a63e913923449b29cac748fba57 (patch) | |
| tree | deaa50b4be11217ae18d2c786fc8bed0d6efa8de | |
| parent | c34fdae510debc8d106a68f60799b64b98c9b2f5 (diff) | |
WIP on getting stores implemented
| -rw-r--r-- | file_store.go | 29 | ||||
| -rw-r--r-- | file_store_test.go | 9 | ||||
| -rw-r--r-- | store.go | 11 |
3 files changed, 49 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) + } + +} diff --git a/file_store_test.go b/file_store_test.go new file mode 100644 index 0000000..b7132a8 --- /dev/null +++ b/file_store_test.go @@ -0,0 +1,9 @@ +package todolist + +import "testing" + +func TestFileStore(t *testing.T) { + store := &FileStore{FileLocation: "todos.json"} + store.Load() + store.Data[0] +} diff --git a/store.go b/store.go new file mode 100644 index 0000000..006583a --- /dev/null +++ b/store.go @@ -0,0 +1,11 @@ +package todolist + +type Store interface { + Load() + Save() + + Find(id int) Todo + Add(t *Todo) + Remove(t *Todo) + NextId() int +} |
