-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (41 loc) · 1.02 KB
/
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
48
49
50
51
package main
import (
"fmt"
"os"
"os/signal"
"github.com/phr3nzy/rescounts-api/http/server"
"github.com/phr3nzy/rescounts-api/internals/config"
"github.com/phr3nzy/rescounts-api/internals/utils/logger"
"go.uber.org/zap"
_ "github.com/joho/godotenv/autoload"
)
func main() {
config := config.GetConfig()
log := logger.GetLoggerInstance()
defer log.Sync()
listenAddress := fmt.Sprintf(
"%s:%d",
config.HOST,
config.PORT,
) // example: localhost:3000, rescounts.com:443
app := server.Bootstrap()
// Handle interrupts and gracefully shutdown.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
<-c
log.Info("Gracefully shutting down...")
if err := app.Shutdown(); err != nil {
log.Error("Failed to gracefully shutdown.", zap.Error(err))
os.Exit(8)
}
}()
// Run our server.
if err := app.Listen(listenAddress); err != nil {
log.Error("Failed to start server.", zap.Error(err))
os.Exit(666)
}
// Handle connection termination here...
// db.Close()
// cache.Shutdown()
}