forked from memnix/memnix-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (66 loc) · 1.97 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
package main
import (
"fmt"
_ "github.com/arsmn/fiber-swagger/v2"
"github.com/memnix/memnixrest/app/controllers"
"github.com/memnix/memnixrest/app/models"
"github.com/memnix/memnixrest/pkg/database"
"github.com/memnix/memnixrest/pkg/routes"
amqp "github.com/rabbitmq/amqp091-go"
"log"
)
// @title Memnix
// @version 1.0
// @description Memnix API
// @securityDefinitions.apikey Beaver
// @in header
// @name Authorization
// @securityDefinitions.apikey Admin
// @in header
// @name Authorization
// @termsOfService https://github.com/memnix/memnix/blob/main/PRIVACY.md
// @contact.name API Support
// @contact.email contact@memnix.app
// @license.name BSD 3-Clause License
// @license.url https://github.com/memnix/memnix-rest/blob/main/LICENSE
// @host http://192.168.1.151:1813/
// @BasePath /v1
func main() { // Try to connect to the database
if err := database.Connect(); err != nil {
log.Panic("Can't connect database:", err.Error())
}
// Create caching session
if err := database.CreateCache(); err != nil {
log.Panic("Can't create caching session:", err.Error())
}
// Connect to RabbitMQ
if _, err := database.Rabbit(); err != nil {
log.Panic("Can't connect to rabbitMq: ", err)
}
// Init the secret key
controllers.Init()
// Disconnect from RabbitMQ*
defer func(conn *amqp.Connection) {
_ = conn.Close()
fmt.Println("Disconnected to RabbitMQ")
}(database.RabbitMqConn)
// Close RabbitMQ channel
defer func(ch *amqp.Channel) {
_ = ch.Close()
}(database.RabbitMqChan)
// Models to migrate
var migrates []interface{}
migrates = append(migrates, models.Access{}, models.Card{}, models.Deck{},
models.User{}, models.Mem{}, models.Answer{}, models.MemDate{}, models.Mcq{})
// AutoMigrate models
for i := 0; i < len(migrates); i++ {
err := database.DBConn.AutoMigrate(&migrates[i])
if err != nil {
log.Panic("Can't auto migrate models:", err.Error())
}
}
// Create the app
app := routes.New()
// Listen to port 1812
log.Panic(app.Listen(":1813"))
}