forked from getevo/evo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evo.go
73 lines (61 loc) · 1.36 KB
/
evo.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
package evo
import (
"log"
dbo "github.com/getevo/evo/v2/lib/db"
"github.com/getevo/evo/v2/lib/generic"
"github.com/getevo/evo/v2/lib/memo"
"github.com/getevo/evo/v2/lib/settings"
"github.com/getevo/evo/v2/lib/settings/database"
"github.com/gofiber/fiber/v2"
)
var (
app *fiber.App
Any func(request *Request) error
)
var http = HTTPConfig{}
var fiberConfig = fiber.Config{}
// Setup set up the EVO app
func Setup() {
var err = settings.Init()
if err != nil {
log.Fatal(err)
}
settings.Register("HTTP", &http)
settings.Get("HTTP").Cast(&http)
err = generic.Parse(http).Cast(&fiberConfig)
if err != nil {
log.Fatal("Unable to retrieve HTTP server configurations: ", err)
}
app = fiber.New(fiberConfig)
if settings.Get("Database.Enabled").Bool() {
db = GetDBO()
dbo.Register(db)
settings.SetDefaultDriver(database.Driver)
}
memo.Register()
}
// Run start EVO Server
func Run() {
if Any != nil {
app.Use(func(ctx *fiber.Ctx) error {
r := Upgrade(ctx)
if err := Any(r); err != nil {
return err
}
return nil
})
} else {
// Last middleware to match anything
app.Use(func(c *fiber.Ctx) error {
c.SendStatus(404)
return nil
})
}
var err error
err = app.Listen(http.Host + ":" + http.Port)
log.Fatal("unable to start web server", "error", err)
}
// GetFiber return fiber instance
func GetFiber() *fiber.App {
return app
}