-
Notifications
You must be signed in to change notification settings - Fork 0
/
worklog.go
52 lines (42 loc) · 1.03 KB
/
worklog.go
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package worklog
import (
"github.com/chonla/homedir"
)
// Worklog is a worklog sheet
type Worklog struct {
home homedir.HomeWrapper
sites []*Site
}
// NewWorklog to create a new worklog instance by giving worklog storage path
func NewWorklog(homeDir homedir.HomeWrapper) (*Worklog, error) {
w := &Worklog{
home: homeDir,
sites: []*Site{},
}
w.ReloadSites()
return w, nil
}
// StoragePath returns path that stores worklog content
func (w *Worklog) StoragePath() string {
return w.home.Path()
}
// SiteList returns site stored in local storage
func (w *Worklog) SiteList() []*Site {
return w.sites
}
// AddSite add a given site to site list
func (w *Worklog) AddSite(s *Site) error {
w.sites = append(w.sites, s)
e := w.saveSite()
return e
}
// ReloadSites read and store sites into internal sites
func (w *Worklog) ReloadSites() error {
e := ReadFile(w.home.With("sites"), &w.sites)
return e
}
// saveSite is to make sites persistent
func (w *Worklog) saveSite() error {
e := WriteFile(w.home.With("sites"), w.sites)
return e
}