forked from rodcorsi/mattermail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
94 lines (72 loc) · 1.81 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"sync"
"github.com/rodcorsi/mattermail/mmail"
)
const defLinesToPreview = 10
// Version show the current version, changed during the make build
var Version = "3.0-dev"
var configFile string
var help bool
var version bool
func init() {
flag.StringVar(&configFile, "config", "./config.json", "Sets the file location for config.json")
flag.StringVar(&configFile, "c", "./config.json", "Sets the file location for config.json")
flag.BoolVar(&help, "h", false, "Show help")
flag.BoolVar(&help, "help", false, "Show help")
flag.BoolVar(&version, "v", false, "Print version")
flag.BoolVar(&version, "version", false, "Print version")
}
const usage = `mattermail [Options]
MatterMail is an integration service for Mattermost, MatterMail listen an email
box and publish all received emails in a channel or private group in Mattermost
Options:
-c, --config Sets the file location for config.json
Default: ./config.json
-h, --help Show this help
-v, --version Print current version
`
func main() {
flag.Parse()
if help {
fmt.Println(usage)
fmt.Println(Version)
return
}
if version {
fmt.Println(Version)
return
}
log.Println("Loading ", configFile)
file, err := ioutil.ReadFile(configFile)
if err != nil {
log.Fatalf("Could not load: %v\n%v", configFile, err.Error())
}
cfgs, err := mmail.ParseConfigList(file)
if err != nil {
log.Fatal(err)
}
hasconfig := false
log.Println("MatterMail version:", Version)
var wg sync.WaitGroup
for _, cfg := range cfgs {
if cfg.Disabled {
continue
}
hasconfig = true
wg.Add(1)
c := cfg
go func() {
mmail.InitMatterMail(c)
wg.Done()
}()
}
wg.Wait()
if !hasconfig {
log.Println(`There is no enabled profile. Check "Disabled" field in config.json`)
}
}