-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
53 lines (42 loc) · 1.42 KB
/
config.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
53
package config
import (
_ "github.com/mailru/easyjson"
"github.com/spf13/viper"
"gopkg.in/yaml.v3"
)
//go:generate go run github.com/mailru/easyjson/easyjson -all config.go
// Global is the configuration for the entire daemon.
type Global struct {
// Accounts are all of the calendar accounts to sync.
Accounts []Account `yaml:"accounts"`
// CalendarDir is the path to the base directory to store calendars in.
CalendarDir string `mapstructure:"calendar_dir" yaml:"calendarDir"`
// TokenDir is the path to store account tokens
TokenDir string `mapstructure:"token_dir"`
}
// Account configures a google account.
type Account struct {
// Name is the human-readable name of the account.
Name string `json:"name"`
// Calendars is the list of calendars to pull from the account.
Calendars []Calendar `json:"calendars"`
// Credentials is credentials JSON file downloaded from Google.
Credentials map[string]interface{} `json:"credentials"`
}
// Calendar configures a google calendar.
type Calendar struct {
// Name is the name of the calendar in Google.
// Likely an email address.
Name string `json:"name"`
// Path is the path to org file to store calendar data.
Path string `json:"path"`
}
// Save updaets the accounts in the configuration file.
func Save(ctx Context, cfg Global) error {
f, err := ctx.FS().Create(viper.ConfigFileUsed())
if err != nil {
return err
}
defer f.Close()
return yaml.NewEncoder(f).Encode(cfg)
}