/
app.go
62 lines (53 loc) · 1.38 KB
/
app.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
package app
import (
"github.com/labstack/echo/v4"
"github.com/myOmikron/echotools/database"
"github.com/myOmikron/echotools/execution"
"github.com/myOmikron/echotools/logging"
"github.com/myOmikron/echotools/middleware"
"github.com/pnp-zone/gorps/handler"
"github.com/pnp-zone/gorps/models"
"gorm.io/driver/sqlite"
"html/template"
)
func StartServer(configPath string) {
logging.Initialize(&logging.Config{})
log := logging.GetLogger("app")
config := ParseConfig(configPath)
e := echo.New()
driver := sqlite.Open("gorps-server.sqlite3")
db := database.Initialize(driver,
&models.Advantage{},
&models.Disadvantage{},
&models.Perk{},
&models.Quirk{},
&models.Modifier{},
&models.Feature{},
&models.PreReqs{},
&models.Skill{},
&models.Character{},
&models.Default{},
)
e.Use(middleware.CustomContext(&handler.Context{}))
e.Use(middleware.Logging(log))
e.Use(middleware.Panic(log))
e.Use(middleware.Session(db, log, &middleware.SessionConfig{}))
// Template rendering
renderer := &TemplateRenderer{
templates: template.Must(template.ParseGlob("templates/*.gohtml")),
}
e.Renderer = renderer
AddRoutes(e, db, config)
execution.SignalStart(e, config.Server.ListenAddress, &execution.Config{
ReloadFunc: func() {
StartServer(configPath)
logging.Stop()
},
StopFunc: func() {
logging.Stop()
},
TerminateFunc: func() {
logging.Stop()
},
})
}