tijl.dev-core/internal/service/main.go
tijl c96824332e
All checks were successful
build / build (push) Successful in 47s
blog update
2024-08-22 20:28:21 +02:00

70 lines
1.7 KiB
Go

package service
import (
"context"
"fmt"
"net/http"
"git.tijl.dev/tijl/tijl.dev-core/internal/assets"
"git.tijl.dev/tijl/tijl.dev-core/internal/config"
"git.tijl.dev/tijl/tijl.dev-core/internal/handlers"
"git.tijl.dev/tijl/tijl.dev-core/internal/i18n"
"git.tijl.dev/tijl/tijl.dev-core/internal/oidc"
webinternal "git.tijl.dev/tijl/tijl.dev-core/internal/web"
"git.tijl.dev/tijl/tijl.dev-core/modules/db"
"git.tijl.dev/tijl/tijl.dev-core/modules/logger"
"git.tijl.dev/tijl/tijl.dev-core/modules/web"
webf "git.tijl.dev/tijl/tijl.dev-core/web"
"github.com/gofiber/contrib/fiberzerolog"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html/v2"
)
func Listen() {
// Load initial context
ctx := context.Background()
// setup logger
log.Load()
// Load config
config.Load()
// Load database
db.Load()
// Setup oidc
oidc.Load(ctx)
// Load assets
assets.Load()
// Load translations
i18n.Load()
// setup handler
handlers.Setup()
// setup web
webinternal.Load()
log.Info().Msg("started internal services")
// Init templating engine
engine := html.NewFileSystem(http.FS(webf.ViewsEmbed), ".html")
engine.Directory = "views"
engine.AddFunc("icon", assets.Svg)
// Init fiber
app := fiber.New(fiber.Config{
Views: engine,
DisableStartupMessage: true,
})
app.Use(fiberzerolog.New(fiberzerolog.Config{
Logger: &log.Logger,
}))
// Setup routes
web.Setup(app)
// Listen web server
log.Info().Int("port", config.Config.Port).Str("host", config.Config.Host).Msg("listening")
if err := app.Listen(fmt.Sprintf("%v:%v", config.Config.Host, config.Config.Port)); err != nil {
log.Fatal().Err(err).Msg("Fiber app error")
}
}