mengstack-api/internal/modules/settings/interfaces/routes.go
MengStack Dev 0eb6a96057 feat(settings): M5 配置管理模块
DB-backed runtime settings with global/tenant scope, key-value store,
type support (string/number/bool/json), tenant-level overrides with
global fallback.
2026-10-03 01:02:53 +08:00

45 lines
1.1 KiB
Go

package interfaces
import (
"mengstack/internal/app/middleware"
"mengstack/internal/modules/settings/application"
"mengstack/internal/modules/settings/infrastructure"
"github.com/gin-gonic/gin"
"go.uber.org/fx"
"go.uber.org/zap"
"gorm.io/gorm"
)
func SetupRoutes(
r *gin.Engine,
h *Handler,
authMW gin.HandlerFunc,
) {
settings := r.Group("/api/v1/settings")
settings.Use(authMW, middleware.MultiTenant())
{
settings.GET("", h.ListGlobalSettings)
settings.GET("/global/:key", h.GetGlobalSetting)
settings.PUT("/global/:key", h.UpdateGlobalSetting)
settings.GET("/tenant", h.ListTenantSettings)
settings.GET("/tenant/:key", h.GetTenantSetting)
settings.PUT("/tenant/:key", h.UpdateTenantSetting)
settings.DELETE("/tenant/:key", h.DeleteTenantSetting)
}
}
var Module = fx.Module("settings",
fx.Provide(
infrastructure.NewSettingRepository,
application.NewService,
NewHandler,
),
fx.Invoke(func(db *gorm.DB, log *zap.Logger) {
if err := infrastructure.Migrate(db); err != nil {
log.Fatal("settings migration failed", zap.Error(err))
}
}),
)