-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (39 loc) · 935 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
package main
import (
"context"
"gateor/internal"
"gateor/pkg"
"net"
"net/http"
"os"
"os/signal"
"syscall"
)
func main() {
mux := internal.InitializeMux()
internal.LoadSvc()
listener, err := net.Listen("tcp", ":8080")
if err != nil {
pkg.Log.Error("Error starting gateor server", "Error", err)
}
defer listener.Close()
server := http.Server{
Handler: mux,
}
// Graceful shutdown
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigChan
pkg.Log.Info("Shutting down gateor")
if err := server.Shutdown(context.Background()); err != nil {
pkg.Log.Error("Error shutting down server", "Error", err)
}
pkg.Log.Info("gateor shutdown complete")
}()
pkg.Log.Info("Gateor starting on ", "Address", listener.Addr().String())
// Start server
if err := server.Serve(listener); err != nil {
pkg.Log.Error("Shutting server", "Error", err)
}
}