-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (55 loc) · 1.4 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Fun fact: This started life as a much simpler Python tool,
// but then I got tired of setting up a new virtualenv every time
// the python version goes up.
package main
import (
"log"
"os"
"github.com/cristalhq/aconfig"
"github.com/cristalhq/aconfig/aconfigyaml"
)
// This gets overridden during build of the release version
var version = "(development)"
// Our configuration.
type NotifyRSSConfig struct {
Mail struct {
Host string
Port int `default:"993"`
Connection string `default:"ssl"`
User string
Pass string
Folder string `default:"INBOX"`
}
Options struct {
Format string `default:"atom"`
}
Files struct {
Aoo string
}
}
func main() {
var err error
var cfg NotifyRSSConfig
cfgFile := "config.yaml"
log.Printf("notifyrss %s starting up", version)
if len(os.Args) == 2 {
cfgFile = os.Args[1]
}
loader := aconfig.LoaderFor(&cfg, aconfig.Config{
SkipFlags: true,
AllowUnknownFields: false,
Files: []string{cfgFile},
FileDecoders: map[string]aconfig.FileDecoder{
".yaml": aconfigyaml.New(),
},
})
err = loader.Load()
if err != nil {
log.Fatalf("can't read config file: %v", err)
}
if cfg.Mail.Host == "" || cfg.Mail.User == "" || cfg.Mail.Pass == "" {
log.Fatalf("IMAP connection is not configured enough to try it")
}
generateFeeds(cfg, acquireEmail(cfg))
log.Printf("done, see you next time.")
}