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
|
package main
/* TODO: Customize logger format when running in a debug state */
/* TODO: Set production logger to the syslog */
import (
"flag"
"os"
"os/signal"
"path/filepath"
"syscall"
"git.thomasvoss.com/euro-cash.eu/pkg/atexit"
. "git.thomasvoss.com/euro-cash.eu/pkg/try"
"git.thomasvoss.com/euro-cash.eu/pkg/watch"
"git.thomasvoss.com/euro-cash.eu/src"
"git.thomasvoss.com/euro-cash.eu/src/dbx"
"git.thomasvoss.com/euro-cash.eu/src/email"
)
func main() {
Try(os.Chdir(filepath.Dir(os.Args[0])))
port := flag.Int("port", 8080, "port number")
debugp := flag.Bool("debug", false, "run in debug mode")
flag.BoolVar(&email.Config.Disabled, "no-email", false,
"disables email support")
flag.StringVar(&email.Config.Host, "smtp-host", "smtp.migadu.com",
"SMTP server hostname")
flag.IntVar(&email.Config.Port, "smtp-port", 465,
"SMTP server port number")
flag.StringVar(&email.Config.ToAddr, "email-to", "bugs@euro-cash.eu",
"address to send error messages to")
flag.StringVar(&email.Config.FromAddr, "email-from", "noreply@euro-cash.eu",
"address to send error messages from")
flag.StringVar(&email.Config.Password, "email-password", "",
"password to authenticate the email client")
flag.StringVar(&dbx.DBName, "db-name", "eurocash.db",
"database name or ‘:memory:’ for an in-memory database")
flag.Parse()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigs
atexit.Exec()
os.Exit(0)
}()
if *debugp {
path := Try2(os.Executable())
go watch.File(path, func() {
atexit.Exec()
Try(syscall.Exec(path, os.Args, os.Environ()))
})
}
dbx.Init(Try2(os.OpenRoot("src/dbx/sql")).FS())
app.BuildTemplates(Try2(os.OpenRoot("src/templates")).FS(), *debugp)
app.Run(*port)
}
|