-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (52 loc) · 1.54 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
60
61
62
63
64
65
package main
import (
"pulse-service/apps/repository/adapter"
"pulse-service/apps/repository/instance"
"pulse-service/apps/routes"
"pulse-service/constants"
"pulse-service/utils"
"context"
"fmt"
"net/http"
"os"
"os/signal"
"pulse-service/logger"
"syscall"
"time"
)
func main() {
logger.InitLogger()
logger.InitEventLogger()
utils.InitSnowflakeNode()
// configs := config.GetConfig()
// aws := instance.GetAwsSession()
RedisDBConnection := instance.GetRedisConnection()
PSqlConnection := instance.GetPSqlConnection()
repository := adapter.RepositoryAdapter(RedisDBConnection, PSqlConnection)
fmt.Println("Starting %s API server", "pulse-service")
server := &http.Server{
Addr: constants.PORT,
Handler: routes.NewRouter().SetRouters(repository),
}
go func() {
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
fmt.Println("Error::%v", err)
fmt.Println("Failed to start %s service\n", "pulse-service")
}
}()
fmt.Println("Listening on port %v ", server.Addr)
// queue := svc.NewServiceRepo(repository).SQSService
// go queue.InitSQS()
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
// The context is used to inform the server it has 5 seconds to finish
// the request it is currently handling
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// Shutdown server
fmt.Println("Shutting down server.")
if err := server.Shutdown(ctx); err != nil {
fmt.Println("Server forced to shutdown: %v\n", err)
}
}