Add comments in main
This commit is contained in:
parent
a6e05ba4c4
commit
500049031a
1 changed files with 21 additions and 7 deletions
28
main.go
28
main.go
|
|
@ -28,11 +28,15 @@ var embedViews embed.FS
|
|||
func main() {
|
||||
log := helpers.GetLogger()
|
||||
|
||||
// Fetch app config
|
||||
config, err := helpers.GetConfig()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Check if at least one account exists
|
||||
// If not, create the default one: admin@invalid.tld / password
|
||||
// Note: since this is the fist call to the DB, this also applies the migrations
|
||||
accountCheck, err := helpers.FirstAccountCheck()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
@ -45,10 +49,13 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
// RegisterJobs
|
||||
// Register background jobs
|
||||
// Note: jobs will be executed at launch and after every interval
|
||||
go helpers.RegisterJob(60*time.Minute, "clean saved sessions", jobs.CleanSavedSessions)
|
||||
|
||||
// Create a new engine
|
||||
// Initialize the Pongo2 templating engine
|
||||
// If we are in dev mode, load templates from directory
|
||||
// Otherwise, use the templates embedded in the binary
|
||||
var engine *django.Engine
|
||||
if config.DevMode {
|
||||
engine = django.New("./views", ".html")
|
||||
|
|
@ -59,26 +66,31 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
engine = django.NewFileSystem(
|
||||
http.FS(embedViews2),
|
||||
".html",
|
||||
)
|
||||
engine = django.NewFileSystem(http.FS(embedViews2), ".html")
|
||||
}
|
||||
|
||||
// Register any custom functions or filters in the template engine
|
||||
pongo2.RegisterFilter("time_diff", helpers.TemplTimeDiff)
|
||||
|
||||
// Base config for the Fiber web app
|
||||
// We pass our newly created template engine
|
||||
// as well as our custom error handler
|
||||
fiberConfig := fiber.Config{
|
||||
Views: engine,
|
||||
ErrorHandler: helpers.FiberErrorHandler,
|
||||
}
|
||||
|
||||
// If app behind proxy, use headers for IP
|
||||
// If web app is behind a reverse proxy,
|
||||
// use X-Forwarded-For header as the IP header
|
||||
if config.App.BehindProxy {
|
||||
fiberConfig.ProxyHeader = fiber.HeaderXForwardedFor
|
||||
}
|
||||
|
||||
// Create the Fiber web app
|
||||
app := fiber.New(fiberConfig)
|
||||
|
||||
// If we are in dev mode, serve assets from directory
|
||||
// Otherwise, serve assets embedded in binary
|
||||
if config.DevMode {
|
||||
app.Static("/static", "./static")
|
||||
} else {
|
||||
|
|
@ -213,6 +225,7 @@ func main() {
|
|||
app.Post("/admin/roles/:id<int;min(0)>/edit", controllers.RoleEdit)
|
||||
app.Post("/admin/roles/:id<int;min(0)>/delete", controllers.RoleDelete)
|
||||
|
||||
// Endpoints only enabled when debug mode is enabled
|
||||
if config.Debug {
|
||||
app.Get("/debug/fake-members/:number<int;min(1)>", controllers.DebugFakeMembers)
|
||||
app.Get("/debug/fake-contacts/:number<int;min(1)>", controllers.DebugFakeContacts)
|
||||
|
|
@ -230,6 +243,7 @@ func main() {
|
|||
config.App.ListenPort,
|
||||
)
|
||||
|
||||
// Start the fiber web app
|
||||
err = app.Listen(listenAddr)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue