-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
41 lines (34 loc) · 954 Bytes
/
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
package main
import (
"encoding/json"
"os"
"time"
)
type Config struct {
WorkDurationMins int `json:"work_duration_mins"`
ShortBreakDurationMins int `json:"short_break_duration_mins"`
LongBreakDurationMins int `json:"long_break_duration_mins"`
ShortBreaks int `json:"short_breaks"`
SendNotification bool `json:"send_notification"`
}
func (c Config) WorkDuration() time.Duration {
return time.Minute * time.Duration(c.WorkDurationMins)
}
func (c Config) ShortBreakDuration() time.Duration {
return time.Minute * time.Duration(c.ShortBreakDurationMins)
}
func (c Config) LongBreakDuration() time.Duration {
return time.Minute * time.Duration(c.LongBreakDurationMins)
}
func ReadConfig() (Config, error) {
var config Config
f, err := os.ReadFile("./config.json")
if err != nil {
return config, err
}
err = json.Unmarshal([]byte(f), &config)
if err != nil {
return config, err
}
return config, nil
}