-
Notifications
You must be signed in to change notification settings - Fork 60
/
main.go
73 lines (61 loc) · 1.49 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
66
67
68
69
70
71
72
73
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/joho/godotenv"
"github.com/robfig/cron"
"github.com/stakwork/sphinx-tribes/auth"
"github.com/stakwork/sphinx-tribes/config"
"github.com/stakwork/sphinx-tribes/db"
"github.com/stakwork/sphinx-tribes/handlers"
"github.com/stakwork/sphinx-tribes/routes"
"github.com/stakwork/sphinx-tribes/websocket"
"gopkg.in/go-playground/validator.v9"
)
func main() {
var err error
err = godotenv.Load()
if err != nil {
fmt.Println("no .env file")
}
db.InitDB()
db.InitRedis()
db.InitCache()
db.InitRoles()
// Config has to be inited before JWT, if not it will lead to NO JWT error
config.InitConfig()
auth.InitJwt()
// validate
db.Validate = validator.New()
// Start websocket pool
go websocket.WebsocketPool.Start()
skipLoops := os.Getenv("SKIP_LOOPS")
if skipLoops != "true" {
go handlers.ProcessTwitterConfirmationsLoop()
go handlers.ProcessGithubIssuesLoop()
}
runCron()
run()
}
func runCron() {
c := cron.New()
c.AddFunc("@every 00h30m00s", handlers.InitV2PaymentsCron)
c.Start()
}
// Start the MQTT plugin
func run() {
router := routes.NewRouter()
shutdownSignal := make(chan os.Signal)
signal.Notify(shutdownSignal, syscall.SIGINT, syscall.SIGTERM)
<-shutdownSignal
// shutdown web server
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := router.Shutdown(ctx); err != nil {
fmt.Printf("error shutting down server: %s", err.Error())
}
}