generated from danthegoodman1/GoAPITemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (42 loc) · 1.22 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"
"github.com/danthegoodman1/EpicEpoch/gologger"
"github.com/danthegoodman1/EpicEpoch/http_server"
"github.com/danthegoodman1/EpicEpoch/raft"
"os"
"os/signal"
"syscall"
"time"
)
var logger = gologger.NewLogger()
func main() {
logger.Debug().Msg("starting epic epoch api")
// start raft
nodeHost, err := raft.StartRaft()
if err != nil {
logger.Error().Err(err).Msg("raft couldn't start")
os.Exit(1)
}
// prometheusReporter := observability.NewPrometheusReporter()
// go func() {
// err := observability.StartInternalHTTPServer(":8042", prometheusReporter)
// if err != nil && !errors.Is(err, http.ErrServerClosed) {
// logger.Error().Err(err).Msg("api server couldn't start")
// os.Exit(1)
// }
// }()
httpServer := http_server.StartHTTPServer(nodeHost)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c
logger.Warn().Msg("received shutdown signal!")
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
if err := httpServer.Shutdown(ctx); err != nil {
logger.Error().Err(err).Msg("failed to shutdown HTTP server")
} else {
logger.Info().Msg("successfully shutdown HTTP server")
}
nodeHost.Stop()
}