-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (37 loc) · 972 Bytes
/
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
package main
import (
"flag"
"fmt"
"log"
)
func main() {
var (
appConfig *AppConfig
err error
)
appConfig = new(AppConfig)
//Standard config
appConfig.SMTP.Host = "localhost"
appConfig.SMTP.Port = 25
appConfig.SMTP.Timeout = 60
appConfig.Debug = false
//Reading params from command line
var port = flag.Int("port", 1323, "port of http service")
var configFilePath = flag.String("config", "app.config.toml", "path to application config file")
//If a config file was informed, let's try to load it
if *configFilePath != "" {
if appConfig, err = loadConfig(*configFilePath); err != nil {
log.Fatalf("failed to load configuration file: %s", err)
}
}
//Mail sender creator
defaultSenderCreator := func() MessageSender {
return MailMessageSender{appConfig.SMTP}
}
// Start server
e, err := createApp(defaultSenderCreator, appConfig.Debug)
if err != nil {
panic(err)
}
e.Logger.Fatal(e.Start(fmt.Sprintf(":%d", *port)))
}