-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
69 lines (55 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
package main
import (
"github.com/button-tech/BNBTextWallet/config"
"github.com/button-tech/BNBTextWallet/db"
"github.com/button-tech/BNBTextWallet/handlers"
"github.com/button-tech/BNBTextWallet/repositories/redisRepository"
"github.com/button-tech/BNBTextWallet/services/discordClient"
"github.com/bwmarrin/discordgo"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"log"
)
func init() {
err := config.EnvConfig.GetEnvs()
if err != nil {
log.Fatal()
}
redisRepository.TryConnect(config.EnvConfig.RedisHost, config.EnvConfig.RedisPassword)
db.TryConnect(config.EnvConfig.Postgres)
}
func main() {
defer redisRepository.Close()
defer db.Close()
go CreateBotSession(config.EnvConfig.BotToken)
router := CreateServer()
if err := router.Run(":5000"); err != nil {
log.Fatal(err)
}
}
func CreateServer() *gin.Engine {
router := gin.Default()
router.Use(gin.Logger())
router.Use(gin.Recovery())
router.Use(cors.Default())
api := router.Group("/api/discord")
{
api.PUT("/create/:guid", handlers.CreateWallet)
api.GET("/transaction/:guid", handlers.Transaction)
api.POST("/transaction/:guid", handlers.InsertTransactionHash)
}
return router
}
func CreateBotSession(token string) {
s, err := discordgo.New("Bot " + token)
if err != nil {
log.Fatal(err)
}
handlers.InitBotHandlers(s)
if err = s.Open(); err != nil {
log.Fatal(err)
}
defer discordClient.Client.Close()
discordClient.Client = &discordClient.DiscordClient{Session: s}
<-make(chan struct{})
}