mirror of
https://github.com/limitcool/starter.git
synced 2025-10-05 16:26:56 +08:00

- 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.
31 lines
734 B
Go
31 lines
734 B
Go
package handler
|
||
|
||
import (
|
||
"github.com/limitcool/starter/configs"
|
||
"github.com/limitcool/starter/internal/pkg/logger"
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// BaseHandler 基础处理器,包含所有Handler的公共字段和方法
|
||
type BaseHandler struct {
|
||
DB *gorm.DB
|
||
Config *configs.Config
|
||
Helper *HandlerHelper
|
||
FileUtil *FileUtil
|
||
}
|
||
|
||
// NewBaseHandler 创建基础处理器
|
||
func NewBaseHandler(db *gorm.DB, config *configs.Config) *BaseHandler {
|
||
return &BaseHandler{
|
||
DB: db,
|
||
Config: config,
|
||
Helper: NewHandlerHelper(),
|
||
FileUtil: NewFileUtil("/uploads"), // 默认基础URL
|
||
}
|
||
}
|
||
|
||
// LogInit 记录Handler初始化日志
|
||
func (h *BaseHandler) LogInit(handlerName string) {
|
||
logger.Info(handlerName + " initialized")
|
||
}
|