This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
85 lines (67 loc) · 1.5 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
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"fmt"
"sync"
"github.com/gin-gonic/gin"
"songguru_bot/models"
"songguru_bot/modules/api"
"songguru_bot/modules/bot"
config "songguru_bot/modules/config/app"
"songguru_bot/modules/config/services"
"songguru_bot/modules/db"
dbModels "songguru_bot/modules/db/models"
"songguru_bot/modules/logging"
"songguru_bot/modules/portal"
)
func NewApp() (*models.App, error) {
// Load services yaml
services, err := services.GetStreamingServices()
if err != nil {
return nil, fmt.Errorf("error loading services yaml: %w", err)
}
// Load config yaml
config, err := config.GetConfig()
if err != nil {
return nil, fmt.Errorf("error loading config yaml: %w", err)
}
// Setup database
db, err := db.SetupDB(config)
if err != nil {
return nil, fmt.Errorf("error setting up database: %w", err)
}
// Clear all web tokens
db.Unscoped().Where("1 = 1").Delete(&dbModels.SettingsWebToken{})
return &models.App{
Config: config,
Services: services,
States: &models.States{Memory: []string{}},
DB: db,
}, nil
}
func main() {
app, err := NewApp()
if err != nil {
logging.PrintLog(err.Error(), err)
panic(err)
}
bot, err := bot.NewBot(app)
if err != nil {
logging.PrintLog(err.Error(), err)
panic(err)
}
var wg sync.WaitGroup
wg.Add(1)
go func() {
router := gin.Default()
portal.StartWebPortal(router, app)
wg.Done()
}()
wg.Add(1)
go func() {
router := gin.Default()
api.StartAPI(router, app)
wg.Done()
}()
bot.Start(app)
wg.Wait()
}