-
Notifications
You must be signed in to change notification settings - Fork 7
/
evo.go
80 lines (67 loc) · 1.56 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
74
75
76
77
78
79
80
package evo
import (
"github.com/getevo/evo/v2/lib/application"
"github.com/getevo/evo/v2/lib/settings"
"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/gofiber/fiber/v2"
)
var (
app *fiber.App
Any func(request *Request) error
)
var http = HTTPConfig{}
var fiberConfig = fiber.Config{}
var Application *application.App
// Setup set up the EVO app
func Setup() {
Application = application.GetInstance()
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.LoadDatabaseSettings()
}
memo.Register()
}
// Run start EVO Server
func Run() {
Application.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
}
func Register(applications ...application.Application) *application.App {
return Application.Register(applications...)
}