-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (51 loc) · 1.38 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
52
53
54
55
56
57
58
59
package main
import (
"base-go-project/controller"
"base-go-project/util"
"context"
"fmt"
"os"
"os/signal"
"strings"
"time"
_ "github.com/joho/godotenv/autoload"
log "github.com/sirupsen/logrus"
)
func main() {
defer func() {
if panicMessage := recover(); panicMessage != nil {
fmt.Printf("Panic '%v' captured ", panicMessage)
}
}()
appConfig := util.InitConfig()
log.Info("Configuring Log...")
// init log file
util.ConfigLog(appConfig.AppName)
log.Info("===========================================")
if strings.ToLower(appConfig.Debug) == "true" {
log.Info("Log level set to DEBUG level")
log.SetLevel(log.DebugLevel)
}
log.Infof("Starting %s apps on port %s", appConfig.AppName, appConfig.Port)
log.Info("Configuring API router...")
router := controller.SetupRouter(appConfig)
router.HideBanner = true
// Start server
serverPort := fmt.Sprintf(":%s", appConfig.Port)
router.Server.Addr = serverPort
go func() {
if err := router.Start(serverPort); err != nil {
router.Logger.Info("shutting down the server")
}
}()
// Wait for interrupt signal to gracefully shut down the server with
// a timeout of 10 seconds.
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
<-quit
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := router.Shutdown(ctx); err != nil {
router.Logger.Fatal(err)
}
}