-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (46 loc) · 1.16 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
package main
import (
"micheltank/cryptocurrency-data-service/cmd/rest"
_ "micheltank/cryptocurrency-data-service/docs"
"micheltank/cryptocurrency-data-service/internal/infra/config"
"os"
"os/signal"
"syscall"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
func main() {
logrus.SetLevel(logrus.DebugLevel)
appConfig := config.Env
err := run(appConfig)
if err != nil {
logrus.WithError(err).
Fatal("failed running application")
return
}
}
func run(appConfig config.Environment) error {
logrus.Info("Starting application")
// REST Server
restApiServer, err := rest.NewServer(appConfig)
if err != nil {
return errors.Wrap(err, "failed to initialize restApiServer")
}
restApiErr := restApiServer.Run()
logrus.Infof("Running http server on port %d", appConfig.Port)
defer restApiServer.Shutdown()
// Shutdown
quit := notifyShutdown()
select {
case err := <-restApiErr:
return errors.Wrap(err, "failed while running restApiServer")
case <-quit:
logrus.Info("Gracefully shutdown")
return nil
}
}
func notifyShutdown() chan os.Signal {
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, syscall.SIGTERM)
return quit
}