change kontor-gin templates
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s

This commit is contained in:
Thomas Peetz
2026-09-24 16:06:38 +02:00
parent ba83d70764
commit 131296c644
26 changed files with 333 additions and 419 deletions
+15 -13
View File
@@ -15,11 +15,23 @@ import (
"github.com/gin-contrib/sessions/cookie"
gin_slog "github.com/gin-contrib/slog"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
)
func main() {
slog.Info("Kontor started")
viper.SetDefault("db.host", "localhost")
viper.SetDefault("db.port", 5432)
viper.SetDefault("db.name", "kontor")
viper.SetDefault("db.user", "kontor")
viper.SetDefault("db.password", "kontor")
viper.SetDefault("port", 8550)
if err := globals.InitConfig(); err != nil {
slog.Info("Failed to initialize config", "error", err)
}
// Set Gin mode based on environment
// Production mode disables debug output
if os.Getenv("GIN_MODE") == "release" {
@@ -57,21 +69,11 @@ func main() {
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)
// Setup Webapp routes
routes.AuthRoutes(router)
routes.ComicRoutes(router)
media := router.Group("/media")
media.Use(middleware.AuthRequired)
routes.MediaRoutes(router)
routes.PublicRoutes(router)
// Start server
port := os.Getenv("PORT")
+9 -43
View File
@@ -2,7 +2,7 @@ package main
import (
// "kontor-api-gin/pkg/handler"
"fmt"
"html/template"
"kontor-api-gin/assets"
"kontor-api-gin/pkg/globals"
@@ -13,8 +13,6 @@ import (
"log"
"log/slog"
"net/http"
"os"
"strings"
"strconv"
"github.com/gin-contrib/sessions"
@@ -24,29 +22,6 @@ import (
"github.com/spf13/viper"
)
func initConfig() error {
viper.SetConfigName("kontor-gin")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("$HOME/.config")
viper.AddConfigPath("/etc/kontor")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
// Read the config file
if err := viper.ReadInConfig(); err != nil {
// Handle the case where config file is not found
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
slog.Info("No config file found, using defaults")
return nil
}
return fmt.Errorf("error reading config file: %w", err)
}
slog.Info("initConfig", "Using config file: ", viper.ConfigFileUsed())
return nil
}
func main() {
slog.Info("Kontor started")
@@ -56,14 +31,15 @@ func main() {
viper.SetDefault("db.user", "kontor")
viper.SetDefault("db.password", "kontor")
viper.SetDefault("port", 8550)
viper.SetDefault("gin.mode", "release")
if err := initConfig(); err != nil {
log.Fatalf("Failed to initialize config: %v", err)
}
if err := globals.InitConfig(); err != nil {
log.Fatalf("Failed to initialize config: %v", err)
}
// Set Gin mode based on environment
// Production mode disables debug output
if os.Getenv("GIN_MODE") == "release" {
if viper.GetString("gin.mode") == "release" {
gin.SetMode(gin.ReleaseMode)
}
@@ -100,21 +76,11 @@ func main() {
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)
// Setup Webapp routes
routes.AuthRoutes(router)
routes.ComicRoutes(router)
media := router.Group("/media")
media.Use(middleware.AuthRequired)
routes.MediaRoutes(router)
routes.PublicRoutes(router)
// Start server
port := viper.GetInt("port")