Files
starter/internal/handler/admin_handler.go
limitcool b7628c770b Refactor user handler and middleware for improved error handling and logging
- Consolidated user ID retrieval and permission checks into helper functions.
- Updated UserHandler to utilize BaseHandler for common database and configuration access.
- Enhanced logging for user-related operations, including login, registration, and password changes.
- Removed redundant context handling in middleware and improved readability.
- Introduced FileUtil for file URL generation and management, encapsulating file-related logic.
- Refactored FileRepo and UserRepo to streamline database operations and error handling.
- Deleted unused request_id middleware and integrated its functionality into request_logger.
- Removed legacy test runner script to simplify testing process.
2025-06-17 23:09:02 +08:00

43 lines
978 B
Go

package handler
import (
"github.com/gin-gonic/gin"
"github.com/limitcool/starter/configs"
"github.com/limitcool/starter/internal/api/response"
"github.com/limitcool/starter/internal/pkg/logger"
"gorm.io/gorm"
)
// AdminHandler 管理员处理器
type AdminHandler struct {
*BaseHandler
}
// NewAdminHandler 创建管理员处理器
func NewAdminHandler(db *gorm.DB, config *configs.Config) *AdminHandler {
handler := &AdminHandler{
BaseHandler: NewBaseHandler(db, config),
}
handler.LogInit("AdminHandler")
return handler
}
// GetSystemSettings 获取系统设置
func (h *AdminHandler) GetSystemSettings(ctx *gin.Context) {
// 获取请求上下文
reqCtx := ctx.Request.Context()
// 记录请求
logger.InfoContext(reqCtx, "GetSystemSettings 获取系统设置")
// 返回系统设置
settings := map[string]any{
"app_name": h.Config.App.Name,
"app_version": "1.0.0",
"app_mode": h.Config.App.Mode,
}
response.Success(ctx, settings)
}