-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
53 lines (44 loc) · 1.15 KB
/
app.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
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/alexsniffin/go-api-starter/internal/todo-api/models"
"github.com/alexsniffin/go-api-starter/internal/todo-api/server"
"github.com/alexsniffin/go-api-starter/pkg/config"
"github.com/alexsniffin/go-api-starter/pkg/logger"
)
const (
configName = "todo-api"
prefix = "TODO"
)
// Entry point to the application.
//
// Exit status codes:
// * 0 - success
// * 1 - from fatal internal error
// * 2 - shutdown timeout
func main() {
newCfg := models.Config{}
err := config.NewConfig(configName, prefix, &newCfg)
if err != nil {
fmt.Println(err)
os.Exit(2)
}
newLogger, err := logger.NewLogger(newCfg)
if err != nil {
fmt.Println(err)
os.Exit(2)
}
newLogger.Info().Msg("setting up todo api service")
newServer := server.NewServer(newCfg, newLogger)
go newServer.Start()
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)
signal.Notify(stop, syscall.SIGTERM)
stopped := <-stop
newLogger.Info().Msg(stopped.String() + " signal received, attempting to gracefully shutdown")
newServer.Shutdown(false)
newLogger.Info().Msg("exiting todo api service")
}