first commit
This commit is contained in:
commit
7cec3bb263
27 changed files with 597 additions and 0 deletions
99
main.go
Normal file
99
main.go
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"git.readonly.ch/bouzoure/popvaud-people/controllers"
|
||||
"git.readonly.ch/bouzoure/popvaud-people/helpers"
|
||||
"git.readonly.ch/bouzoure/popvaud-people/middlewares"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
||||
"github.com/gofiber/template/pug/v2"
|
||||
)
|
||||
|
||||
//go:embed static/*
|
||||
var embedStatic embed.FS
|
||||
|
||||
//go:embed views
|
||||
var embedViews embed.FS
|
||||
|
||||
func main() {
|
||||
config, err := helpers.GetConfig()
|
||||
if err != nil {
|
||||
// TODO: Handle exception
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = helpers.GetDatabase()
|
||||
if err != nil {
|
||||
// TODO: Handle exception
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
accountCheck, err := helpers.FirstAccountCheck()
|
||||
if err != nil {
|
||||
// TODO: Handle exception
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if !accountCheck {
|
||||
err = helpers.FirstAccountCreate()
|
||||
if err != nil {
|
||||
// TODO: Handle exception
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new engine
|
||||
var engine *pug.Engine
|
||||
if config.Debug {
|
||||
engine = pug.New("./views", ".pug")
|
||||
engine.ShouldReload = true
|
||||
} else {
|
||||
embedViews2, err := fs.Sub(embedViews, "views")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
engine = pug.NewFileSystem(
|
||||
http.FS(embedViews2),
|
||||
".pug",
|
||||
)
|
||||
}
|
||||
|
||||
app := fiber.New(fiber.Config{
|
||||
Views: engine,
|
||||
})
|
||||
|
||||
if config.Debug {
|
||||
app.Static("/static", "./static")
|
||||
} else {
|
||||
app.Use("/static", filesystem.New(filesystem.Config{
|
||||
Root: http.FS(embedStatic),
|
||||
PathPrefix: "static",
|
||||
Browse: false,
|
||||
}))
|
||||
}
|
||||
|
||||
// Middlewares
|
||||
app.Use(middlewares.AuthMiddleware)
|
||||
|
||||
// Controllers
|
||||
app.Get("/", controllers.Homepage)
|
||||
app.Get("/login", controllers.LoginForm)
|
||||
|
||||
listenAddr := fmt.Sprintf(
|
||||
"%s:%d",
|
||||
config.App.ListenAddress,
|
||||
config.App.ListenPort,
|
||||
)
|
||||
|
||||
err = app.Listen(listenAddr)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue