-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (52 loc) · 1.35 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
package main
import (
"flag"
"log"
"os/signal"
"os"
"github.com/alex-emery/mailfeed/internal/service"
"github.com/joho/godotenv"
"go.uber.org/zap"
)
func main() {
dbPath := flag.String("db", "mailfeed.db", "path to sqlite database")
port := flag.String("port", "8080", "port to run server on")
host := flag.String("host", "localhost", "host to run server on")
flag.Parse()
_ = godotenv.Load()
emailUsername := os.Getenv("EMAIL_USERNAME")
emailPassword := os.Getenv("EMAIL_PASSWORD")
emailServer := os.Getenv("EMAIL_SERVER")
logger, err := zap.NewDevelopment()
if err != nil {
log.Fatal("failed to create logger", err)
}
defer func() {
if err := logger.Sync(); err != nil {
log.Fatal("failed to sync logger", err)
}
}()
options := service.ServiceOptions{
EmailServer: emailServer,
EmailUsername: emailUsername,
EmailPassword: emailPassword,
DBPath: *dbPath,
Port: *port,
Domain: *host,
}
svc, err := service.New(logger, options)
if err != nil {
logger.Fatal("failed to create service", zap.Error(err))
}
go func() {
if err := svc.Start(); err != nil {
logger.Fatal("failed to start service", zap.Error(err))
}
}()
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt)
<-sigChan
if err := svc.Stop(); err != nil {
log.Fatal("failed to shutdown service", err)
}
}