aboutsummaryrefslogtreecommitdiffstats
path: root/file_store.go
blob: 03704f9fcfce3855ec6e8c2c0e86d72aafde76a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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)
	}

}