-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
60 lines (50 loc) · 1.62 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
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"time"
"github.com/jcmturner/authenvoy/config"
"github.com/jcmturner/authenvoy/httphandling"
)
const appTitle = "Authentication Envoy"
var buildhash = "Not set"
var buildtime = "Not set"
func main() {
version := flag.Bool("version", false, "Print version information.")
logs := flag.String("log-dir", "./", "Directory to output logs to.")
port := flag.Int("port", 8088, "Port to listen on loopback.")
krbconf := flag.String("krb5-conf", "./krb5.conf", "Path to krb5.conf file.")
tls := flag.Bool("tls", false, "Enable TLS using self signed certificate.")
flag.Parse()
// Print version information and exit.
if *version {
fmt.Fprintf(os.Stderr, versionStr())
os.Exit(0)
}
c, err := config.New(*port, *krbconf, *logs)
if err != nil {
fmt.Fprintf(os.Stderr, "%s configuration error: %v", appTitle, err)
os.Exit(1)
}
socket := fmt.Sprintf("%s:%d", "127.0.0.1", c.Port)
c.ApplicationLogf(versionStr())
if *tls {
err = httphandling.ListenAndServeTLS(socket, httphandling.NewRouter(c))
} else {
err = http.ListenAndServe(socket, httphandling.NewRouter(c))
}
log.Fatalf("%s exit: %v\n", appTitle, err)
}
// Version returns the version number, hash from git and the time of the build.
func versionInfo() (string, time.Time) {
bt, _ := time.Parse(time.RFC3339, buildtime)
return buildhash, bt
}
// VersionStr returns the version number, hash from git and the time of the build in a pretty formatted string.
func versionStr() string {
bh, bt := versionInfo()
return fmt.Sprintf("%s Version Information:\nBuild hash:\t%s\nBuild time:\t%v\n", appTitle, bh, bt)
}