aboutsummaryrefslogtreecommitdiffstats
path: root/todolist/file_store.go
diff options
context:
space:
mode:
authorGrant Ammons <gammons@gmail.com>2017-06-12 06:52:24 -0400
committerGrant Ammons <gammons@gmail.com>2017-06-12 06:52:24 -0400
commit8d3cc3ca53d6ca10a35376a4613975718ceefef7 (patch)
tree0676a1e3982b4933b5b53c5fc34d88dd904dcb27 /todolist/file_store.go
parent4a91b284cc1840ad4dc4e60e831c8c6e3de283de (diff)
Re-order functions in file_store
Diffstat (limited to 'todolist/file_store.go')
-rw-r--r--todolist/file_store.go53
1 files changed, 27 insertions, 26 deletions
diff --git a/todolist/file_store.go b/todolist/file_store.go
index a6fa0d7..e92f2d7 100644
--- a/todolist/file_store.go
+++ b/todolist/file_store.go
@@ -17,17 +17,21 @@ func NewFileStore() *FileStore {
return &FileStore{FileLocation: "", Loaded: false}
}
-func getLocation() string {
- localrepo := ".todos.json"
- usr, _ := user.Current()
- homerepo := fmt.Sprintf("%s/.todos.json", usr.HomeDir)
- _, ferr := os.Stat(localrepo)
+func (f *FileStore) Initialize() {
+ if f.FileLocation == "" {
+ f.FileLocation = ".todos.json"
+ }
- if ferr == nil {
- return localrepo
- } else {
- return homerepo
+ _, err := ioutil.ReadFile(f.FileLocation)
+ if err == nil {
+ fmt.Println("It looks like a .todos.json file already exists! Doing nothing.")
+ os.Exit(0)
+ }
+ if err := ioutil.WriteFile(f.FileLocation, []byte("[]"), 0644); err != nil {
+ fmt.Println("Error writing json file", err)
+ os.Exit(1)
}
+ fmt.Println("Todo repo initialized.")
}
func (f *FileStore) Load() ([]*Todo, error) {
@@ -55,26 +59,23 @@ func (f *FileStore) Load() ([]*Todo, error) {
return todos, nil
}
-func (f *FileStore) Initialize() {
- if f.FileLocation == "" {
- f.FileLocation = ".todos.json"
- }
-
- _, err := ioutil.ReadFile(f.FileLocation)
- if err == nil {
- fmt.Println("It looks like a .todos.json file already exists! Doing nothing.")
- os.Exit(0)
- }
- if err := ioutil.WriteFile(f.FileLocation, []byte("[]"), 0644); err != nil {
- fmt.Println("Error writing json file", err)
- os.Exit(1)
- }
- fmt.Println("Todo repo initialized.")
-}
-
func (f *FileStore) Save(todos []*Todo) {
data, _ := json.Marshal(todos)
if err := ioutil.WriteFile(f.FileLocation, []byte(data), 0644); err != nil {
fmt.Println("Error writing json file", err)
}
}
+
+func getLocation() string {
+ localrepo := ".todos.json"
+ usr, _ := user.Current()
+ homerepo := fmt.Sprintf("%s/.todos.json", usr.HomeDir)
+ _, ferr := os.Stat(localrepo)
+
+ if ferr == nil {
+ return localrepo
+ } else {
+ return homerepo
+ }
+}
+