change kontor-gin for containers
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s

This commit is contained in:
Thomas Peetz
2026-09-23 17:09:48 +02:00
parent 6b5167a5c0
commit a0ad4e5c26
23 changed files with 295 additions and 172 deletions
+88
View File
@@ -0,0 +1,88 @@
package main
import (
// "kontor-api-gin/pkg/handler"
"kontor-api-gin/pkg/globals"
"kontor-api-gin/pkg/middleware"
"kontor-api-gin/pkg/routes"
"kontor-api-gin/pkg/schema"
"log"
"log/slog"
"os"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
gin_slog "github.com/gin-contrib/slog"
"github.com/gin-gonic/gin"
)
func main() {
slog.Info("Kontor started")
// Set Gin mode based on environment
// Production mode disables debug output
if os.Getenv("GIN_MODE") == "release" {
gin.SetMode(gin.ReleaseMode)
}
// Connect to database
schema.Connect()
// Run migrations
schema.RunMigrations()
// Create Gin router with default middleware
// Default includes Logger and Recovery middleware
// router := gin.Default()
// Create a new router without default mmiddleware
router := gin.New()
// Add recovery middleware
router.Use(gin.Recovery())
router.Use(gin_slog.SetLogger(
gin_slog.WithSkipPath([]string{"/health", "/public/style/main.css"}),
gin_slog.WithDefaultLevel(slog.LevelInfo),
gin_slog.WithClientErrorLevel(slog.LevelInfo),
gin_slog.WithServerErrorLevel(slog.LevelInfo),
))
router.LoadHTMLGlob("templates/**/*.html")
router.Static("/public", "./assets")
router.Use(sessions.Sessions("session", cookie.NewStore(globals.Secret)))
// Setup api routes
api := routes.SetupApiRoutes(router)
api.Use(middleware.CorsMiddleware)
routes.SetupMediaRoutes(api)
routes.SetupComicRoutes(api)
// Setup public Webapp routes
routes.PublicRoutes(router)
// Setup protected Webapp routes
protected := router.Group("/auth")
protected.Use(middleware.AuthRequired)
routes.ProtectedRoutes(router)
comics := router.Group("/comics")
comics.Use(middleware.AuthRequired)
routes.ComicRoutes(router)
media := router.Group("/media")
media.Use(middleware.AuthRequired)
routes.MediaRoutes(router)
// Start server
port := os.Getenv("PORT")
if port == "" {
port = "8550"
}
slog.Info("Server starting", "port", port)
if err := router.Run(":" + port); err != nil {
log.Fatal("Failed to start server:", err)
}
slog.Info("Kontor finished")
}
+1 -1
View File
@@ -49,7 +49,7 @@ func main() {
gin_slog.WithServerErrorLevel(slog.LevelInfo),
))
templ := template.Must(template.New("").ParseFS(templates.TemplateFiles, "html/*.tmpl"))
templ := template.Must(template.New("").ParseFS(templates.TemplateFiles, "layouts/*.html", "pages/*.html"))
router.SetHTMLTemplate(templ)
router.StaticFS("/public", http.FS(assets.StaticFiles))