diff options
| author | Grant Ammons <grant@pipelinedealsco.com> | 2016-09-19 05:27:44 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-09-19 05:27:44 -0400 |
| commit | c3c8817de6228557ba865465e3d639a104578587 (patch) | |
| tree | b5e004011606f1cc44eba196bff8f1bd33e795b7 /todolist/file_store.go | |
| parent | aa0580af8066b030c720a20b5e79e98a53d1ec11 (diff) | |
| parent | 144ac3243b4920d267f224732d9deff0f9f2cc52 (diff) | |
Merge pull request #9 from Bunchhieng/master
Only allow to open web app if .todos.json exists in current directory
Diffstat (limited to 'todolist/file_store.go')
| -rw-r--r-- | todolist/file_store.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/todolist/file_store.go b/todolist/file_store.go index 61e6e7c..5413295 100644 --- a/todolist/file_store.go +++ b/todolist/file_store.go @@ -16,11 +16,12 @@ func NewFileStore() *FileStore { return &FileStore{FileLocation: ".todos.json", Loaded: false} } -func (f *FileStore) Load() []*Todo { +func (f *FileStore) Load() ([]*Todo, error) { data, err := ioutil.ReadFile(f.FileLocation) if err != nil { fmt.Println("No todo file found!") fmt.Println("Initialize a new todo repo by running 'todo init'") + return nil, err os.Exit(0) } @@ -28,11 +29,12 @@ func (f *FileStore) Load() []*Todo { jerr := json.Unmarshal(data, &todos) if jerr != nil { fmt.Println("Error reading json data", jerr) + return nil, jerr os.Exit(1) } f.Loaded = true - return todos + return todos, nil } func (f *FileStore) Initialize() { |
