-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
52 lines (43 loc) · 854 Bytes
/
Copy pathmain.go
File metadata and controls
52 lines (43 loc) · 854 Bytes
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
package main
import (
"github.com/Daniel-W-Innes/hermes/models"
"github.com/Daniel-W-Innes/hermes/routes"
"github.com/Daniel-W-Innes/hermes/utils"
"github.com/gofiber/fiber/v2"
"log"
)
func health(c *fiber.Ctx) error {
return c.SendString("ok")
}
func initDB(config *models.DBConfig) error {
db, hermesError := utils.Connection(config)
if hermesError != nil {
return hermesError
}
err := db.AutoMigrate(&models.Message{}, &models.User{})
if err != nil {
return err
}
return nil
}
func getApp() *fiber.App {
app := fiber.New()
app.Get("/", health)
routes.User(app)
routes.Message(app)
return app
}
func main() {
config, err := models.GetConfig()
if err != nil {
log.Panic(err)
}
err = initDB(&config.DBConfig)
if err != nil {
log.Panic(err)
}
err = getApp().Listen(":8080")
if err != nil {
log.Panic(err)
}
}