summaryrefslogtreecommitdiffhomepage
path: root/main.go
blob: c8dead493c41cb33c30c4934cf677f47bb3a0adb (plain) (blame)
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
package main

/* TODO: Customize logger format when running in a debug state */
/* TODO: Set production logger to the syslog */

import (
	"flag"
	"log"
	"os"
	"syscall"
	"time"

	"git.thomasvoss.com/euro-cash.eu/src"
	"git.thomasvoss.com/euro-cash.eu/src/email"
)

func main() {
	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.Parse()

	if *debugp {
		go watch()
	}
	src.Run(*port)
}

func watch() {
	path, err := os.Executable()
	if err != nil {
		die(err)
	}

	ostat, err := os.Stat(path)
	if err != nil {
		die(err)
	}

	for {
		nstat, err := os.Stat(path)
		if err != nil {
			die(err)
		}

		if nstat.ModTime() != ostat.ModTime() {
			if err := syscall.Exec(path, os.Args, os.Environ()); err != nil {
				die(err)
			}
		}

		time.Sleep(1 * time.Second)
	}
}

func die(err error) {
	log.Fatal(err)
	os.Exit(1)
}