Add SIGTERM handler and logging
Also change port to default http
This commit is contained in:
parent
4a0a91a1f1
commit
b5b41c95a5
1 changed files with 19 additions and 1 deletions
20
main.go
20
main.go
|
@ -1,17 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
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
|
||||
router := NewRouter()
|
||||
|
||||
fmt.Println("Initialised")
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue