-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (38 loc) · 1016 Bytes
/
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
//go:generate go run -tags=dev files/assets_generate.go
// Copyright 2020 Tim Shannon. All rights reserved.
// Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.
package main
import (
"flag"
"log"
"os"
"os/signal"
"github.com/timshannon/threenamesinahat/server"
)
var flagPort string
func init() {
flag.StringVar(&flagPort, "port", "8080", "Port for the webserver to listen on")
}
func main() {
flag.Parse()
//Capture program shutdown, to make sure everything shuts down nicely
c := make(chan os.Signal, 1)
shutdown := make(chan bool)
go func() {
signal.Notify(c, os.Interrupt)
for sig := range c {
if sig == os.Interrupt {
log.Print("Three Names in a Hat server is shutting down")
shutdown <- true
}
}
}()
log.Printf("Starting web server on port %s", flagPort)
err := server.Start(flagPort, shutdown)
if err != nil {
log.Fatalf("Fatal web server error: %s", err)
}
log.Print("Server Shutdown Successfully")
os.Exit(0)
}