-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (36 loc) · 840 Bytes
/
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
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
"web3-services/practice/services"
"github.com/gin-gonic/gin"
)
func main() {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
loadDotEnv()
mysqldb := connectMySQL()
mongoClient := connectMongoClient()
mongodb := connectMongoDB(mongoClient)
rpcClient := establishRPC()
go func() {
// Run per 15 seconds
ticker := time.NewTicker(15 * time.Second)
for range ticker.C {
services.IndexBlockRPC(mongodb, mysqldb, rpcClient, 0)
}
}()
router := gin.Default()
setupRoutes(router, mongodb, mysqldb)
go router.Run("localhost:8080")
select {
case <-sigChan:
fmt.Println("Received interrupt signal. Cleaning up...")
handleMySQLDisconnected(mysqldb)
handleMongoDisconnected(mongoClient)
os.Exit(0)
}
}