-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
43 lines (35 loc) · 742 Bytes
/
Copy pathmain.go
File metadata and controls
43 lines (35 loc) · 742 Bytes
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
package main
import (
"net/http"
"log"
"fmt"
"os"
"os/signal"
"syscall"
)
// Global connection to be used by the server
var DB = Database{}
func main() {
// Register the cleanup listener:
c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
cleanup()
os.Exit(1)
}()
// Initialise DB connections
fmt.Println("Initialising database connection")
DB.Open()
fmt.Println("Connection initialised")
// Initialise router
fmt.Println("Starting webserver...")
fmt.Println("Listening on port: " + PORT)
router := CreateRouter()
log.Fatal(http.ListenAndServe(":" + PORT, router))
}
func cleanup() {
fmt.Println("Beginning clean-up")
DB.Close()
fmt.Println("Finished clean-up")
}