-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (40 loc) · 1.08 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 (
"context"
"errors"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/sirupsen/logrus"
"github.com/maknahar/alpha-flow/internal/configs"
"github.com/maknahar/alpha-flow/internal/routes"
)
func main() {
config, err := configs.Configure(context.Background())
if err != nil {
logrus.WithError(err).Panic("Unable to start the application. Error in configuration.")
}
server := &http.Server{
Addr: config.Host,
Handler: routes.Get(config),
}
config.Logger.Info("Starting the service on ", config.Host)
go func() {
if sErr := server.ListenAndServe(); sErr != nil && !errors.Is(sErr, http.ErrServerClosed) {
config.Logger.Fatal(sErr)
}
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
config.Logger.Info("Service is shutting down")
timeoutCtx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
if err = server.Shutdown(timeoutCtx); err != nil {
config.Logger.Errorln("Error during HTTP server shutdown:", err)
}
log.Println("Service Stopped")
}