Add SIGTERM handler and logging

Also change port to default http
This commit is contained in:
Marc Di Luzio 2020-05-29 18:13:26 +01:00
parent 4a0a91a1f1
commit b5b41c95a5

20
main.go
View file

@ -1,17 +1,35 @@
package main package main
import ( import (
"fmt"
"log" "log"
"net/http" "net/http"
"os"
"os/signal"
"syscall"
) )
func main() { func main() {
fmt.Println("Initialising...")
// Set up the close handler
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
fmt.Println("SIGTERM recieved, exiting...")
os.Exit(0)
}()
// Create a new router // Create a new router
router := NewRouter() router := NewRouter()
fmt.Println("Initialised")
// Listen and serve the http requests // Listen and serve the http requests
if err := http.ListenAndServe(":8080", router); err != nil { fmt.Println("Serving HTTP")
if err := http.ListenAndServe(":80", router); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }