/
main.go
72 lines (62 loc) · 1.71 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
package main
import (
"os"
_ "github.com/gibigo/cornix-tv-channel/docs"
"github.com/gibigo/cornix-tv-channel/internal/api/dal"
"github.com/gibigo/cornix-tv-channel/internal/api/routes"
"github.com/gibigo/cornix-tv-channel/internal/config"
"github.com/gibigo/cornix-tv-channel/internal/config/database"
"github.com/gibigo/cornix-tv-channel/internal/telegram/handler"
"github.com/gibigo/cornix-tv-channel/internal/utils/logging"
"github.com/gofiber/fiber/v2"
)
func main() {
// load the configuration
cfg := loadConfiguration()
// init the logger
logging.Init(cfg.Logging)
// who would have thought, connects to the database
database.Connect(cfg.Database)
// create the database structure
tables := []interface{}{
&dal.User{},
&dal.TVSignal{},
&dal.Channel{},
&dal.Strategy{},
&dal.ZoneStrategy{},
&dal.TargetStrategy{},
&dal.Entry{},
&dal.TP{},
&dal.SL{},
}
database.Migrate(tables...)
// create the telegram bot
bot := cfg.Telegram.NewBot()
// start the channel message handler (to delete closed trades from the database)
go handler.StartTGHandler(bot)
// lets fire up the API
app := fiber.New()
routes.SetupRoutes(app)
app.Listen(":3000")
}
func loadConfiguration() *config.Config {
var err error
customConfigFile := os.Getenv("CONFIG_FILE")
if len(customConfigFile) > 0 {
err = config.Load(customConfigFile)
} else {
err = config.Load(config.DefaultConfigurationFilePath)
}
if err != nil {
panic(err)
}
cfg := config.Get()
return cfg
}
// @title Cornix-TV-Channel API
// @version 1.0
// @host https://yourforwarder.io
// @BasePath /api/v1
// @license.name GPLv3
// @license.url https://github.com/gibigo/cornix-tv-channel/blob/master/LICENSE
// @securityDefinitions.basic BasicAuth