summaryrefslogtreecommitdiffhomepage
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go37
1 files changed, 36 insertions, 1 deletions
diff --git a/main.go b/main.go
index 5bf0a51..a9b9ea7 100644
--- a/main.go
+++ b/main.go
@@ -1,14 +1,29 @@
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",
@@ -21,7 +36,27 @@ func main() {
"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()
- src.Run(*port)
+ 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)
}