-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (61 loc) · 1.88 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
package main
import (
"crypto/ed25519"
"encoding/hex"
"fmt"
"os"
"strings"
leaderboard "github.com/NetSepio/gateway/api/v1/leaderboard"
"github.com/NetSepio/gateway/app"
"github.com/NetSepio/gateway/config/dbconfig"
"github.com/NetSepio/gateway/config/envconfig"
"github.com/NetSepio/gateway/models"
"github.com/NetSepio/gateway/models/claims"
"github.com/NetSepio/gateway/util/pkg/auth"
"github.com/NetSepio/gateway/util/pkg/logwrapper"
"github.com/robfig/cron"
)
func main() {
app.Init()
db := dbconfig.GetDb()
// pub, priv, _ := ed25519.GenerateKey(rand.Reader)
// fmt.Printf("priv = %s\npub = %s\n", hex.EncodeToString(priv), hex.EncodeToString(pub))
if os.Getenv("DEBUG_MODE") == "true" {
walletAddrLower := strings.ToLower("0xdd3933022e36e9a0a15d0522e20b7b580d38b54ec9cb28ae09697ce0f7c95b6b")
newUser := &models.User{
WalletAddress: &walletAddrLower,
UserId: "fc8fe270-ce16-4df9-a17f-979bcd824e32",
}
if err := db.Create(newUser).Error; err != nil {
logwrapper.Warn(err)
}
newClaims := claims.NewWithWallet(newUser.UserId, newUser.WalletAddress)
pvKey, err := hex.DecodeString(envconfig.EnvVars.PASETO_PRIVATE_KEY[2:])
if err != nil {
panic(err)
}
token, err := auth.GenerateToken(newClaims, ed25519.PrivateKey(pvKey))
if err != nil {
panic(err)
}
fmt.Printf("========TEST TOKEN========\n%s\n========TEST TOKEN========\n", token)
}
dbconfig.Migrate()
go func() {
c := cron.New()
// Schedule the function to run every day at midnight (or adjust the schedule as needed)
c.AddFunc("0 30 18 * * *", func() {
leaderboard.AutoCalculateScoreBoard()
})
// Start the cron scheduler in the background
c.Start()
// Keep the application running
select {}
}()
logwrapper.Log.Info("Starting app")
addr := fmt.Sprintf(":%d", envconfig.EnvVars.APP_PORT)
err := app.GinApp.Run(addr)
if err != nil {
logwrapper.Log.Fatal(err)
}
}