tijl.dev-core/internal/service/main.go
tijl d77d2cc94c
All checks were successful
build / build (push) Successful in 51s
web changes + blog implementation
2024-08-22 18:04:08 +02:00

73 lines
1.7 KiB
Go

package service
import (
"context"
"fmt"
"net/http"
"time"
"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()
start := time.Now()
// 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()
// 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)
log.Info().Int64("ms", time.Since(start).Milliseconds()).Msg("started internal services")
// 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")
}
}