forked from zorchenhimer/MoviePolls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (63 loc) · 1.58 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
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"flag"
"fmt"
"net/http"
"os"
"github.com/zorchenhimer/MoviePolls/database"
"github.com/zorchenhimer/MoviePolls/logger"
"github.com/zorchenhimer/MoviePolls/logic"
"github.com/zorchenhimer/MoviePolls/web"
)
var ReleaseVersion string
func main() {
var logFile string
var logLevel string
var debug bool
var version bool
flag.StringVar(&logFile, "logfile", "logs/server.log", "File to write logs")
flag.StringVar(&logLevel, "loglevel", "debug", "Log verbosity")
flag.BoolVar(&debug, "debug", false, "Enable debug code")
flag.BoolVar(&version, "version", true, "Show the version of the binary file")
flag.Parse()
log, err := logger.NewLogger(logger.LogLevel(logLevel), logFile)
if err != nil {
fmt.Printf("Unable to load logger: %v\n", err)
os.Exit(1)
}
config := web.Options{
Debug: debug,
Listen: ":8090",
}
if version {
log.Info("Running version: %s", ReleaseVersion)
}
if config.Debug {
log.Info("Debug mode turned on")
}
// init database
data, err := database.GetDatabase("json", "db/data.json", log)
if err != nil {
fmt.Printf("Unable to load json data: %v\n", err)
os.Exit(1)
}
// init logic
backend, err := logic.New(data, log)
if err != nil {
fmt.Printf("Unable to load backend: %v\n", err)
os.Exit(1)
}
// init frontend
frontend, err := web.New(config, backend, log)
if err != nil {
fmt.Printf("Unable to load frontend: %v\n", err)
os.Exit(1)
}
// run frontend
err = frontend.ListenAndServe()
if err != http.ErrServerClosed {
fmt.Printf("Error serving: %v\n", err)
os.Exit(1)
}
fmt.Println("goodbye")
}