umstellung auf Service und Repository Verwendung - WIP
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s

This commit is contained in:
Thomas Peetz
2026-09-25 16:57:23 +02:00
parent 131296c644
commit f0f1819a1f
42 changed files with 998 additions and 351 deletions
+49
View File
@@ -0,0 +1,49 @@
package router
import (
"html/template"
"kontor-api-gin/assets"
"kontor-api-gin/internal/handlers"
"kontor-api-gin/internal/middleware"
"kontor-api-gin/templates"
"net/http"
"log/slog"
"github.com/gin-contrib/cors"
gin_slog "github.com/gin-contrib/slog"
"github.com/gin-gonic/gin"
)
func New(comics *handlers.ComicHandler, auth *handlers.AuthHandler, secret []byte) *gin.Engine {
router := gin.New()
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.Use(cors.New(cors.Config{
AllowOrigins: []string{"https://app.example.com"},
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE"},
AllowHeaders: []string{"Authorization", "Content-Type"},
}))
templ := template.Must(template.New("").ParseFS(templates.TemplateFiles, "layouts/*.html", "pages/*.html"))
router.SetHTMLTemplate(templ)
router.StaticFS("/public", http.FS(assets.StaticFiles))
router.GET("/health", func(c *gin.Context) { c.JSON(200, gin.H{"ok": true}) })
api := router.Group("/api")
api.POST("/login", auth.Login)
v1 := api.Group("/v1")
{
secured := v1.Group("")
secured.Use(middleware.JWT(secret))
secured.GET("comics/comics", comics.List)
}
return router
}