-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (52 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
package main
import (
"fmt"
"net/http"
"os"
log "github.com/sirupsen/logrus"
"github.com/ashleyprimo/go-qr-generator/documentation"
"github.com/ashleyprimo/go-qr-generator/initialize"
"github.com/ashleyprimo/go-qr-generator/qr"
)
func loglevel(opt string) {
switch opt {
case "error":
log.SetLevel(log.ErrorLevel)
case "warn":
log.SetLevel(log.WarnLevel)
case "info":
log.SetLevel(log.InfoLevel)
case "debug":
log.SetLevel(log.DebugLevel)
default:
log.Warnln("Unrecognized log level, will default to `info` log level")
}
}
func health(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("Ping."))
}
func main() {
initialize.Flags()
if *initialize.VersionFlag {
fmt.Printf("%s v%s", initialize.ApplicationName, initialize.Version)
os.Exit(0)
}
loglevel(*initialize.LogLevel)
metrics()
// QR Engine API Endpoint
http.HandleFunc(*initialize.QREndpoint, qr.Engine)
// Documentation Endpoint
if *initialize.EnableDocs {
log.Debugf("Documentation Endpoint Enabled")
http.HandleFunc("/docs", docs.Landing)
}
// Health Check Endpoint
http.HandleFunc("/health", health)
log.Infof("Listening for requests on %s:%s", *initialize.Host, *initialize.PortNumber)
if *initialize.Https {
log.Fatalf("Failed to start web server with TLS: %s", http.ListenAndServeTLS(fmt.Sprintf("%s:%s", *initialize.Host, *initialize.PortNumber), *initialize.Server_crt, *initialize.Server_key, nil))
} else {
log.Fatalf("Failed to start web server: %s", http.ListenAndServe(fmt.Sprintf("%s:%s", *initialize.Host, *initialize.PortNumber), nil))
}
}