mirror of
https://github.com/skyle1995/NetworkAuth.git
synced 2026-05-25 02:24:05 +08:00
Add classification annotations
This commit is contained in:
@@ -10,14 +10,26 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// ============================================================================
|
||||
// 结构体定义
|
||||
// ============================================================================
|
||||
|
||||
// BaseController 基础控制器结构体
|
||||
type BaseController struct{}
|
||||
|
||||
// ============================================================================
|
||||
// 构造函数
|
||||
// ============================================================================
|
||||
|
||||
// NewBaseController 创建基础控制器实例
|
||||
func NewBaseController() *BaseController {
|
||||
return &BaseController{}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 数据库相关方法
|
||||
// ============================================================================
|
||||
|
||||
// GetDB 获取数据库连接,统一错误处理
|
||||
func (bc *BaseController) GetDB(c *gin.Context) (*gorm.DB, bool) {
|
||||
db, err := database.GetDB()
|
||||
@@ -28,6 +40,10 @@ func (bc *BaseController) GetDB(c *gin.Context) (*gorm.DB, bool) {
|
||||
return db, true
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 错误处理方法
|
||||
// ============================================================================
|
||||
|
||||
// HandleDatabaseError 统一处理数据库连接错误
|
||||
func (bc *BaseController) HandleDatabaseError(c *gin.Context, err error) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
@@ -64,6 +80,10 @@ func (bc *BaseController) HandleInternalError(c *gin.Context, message string, er
|
||||
})
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 成功响应方法
|
||||
// ============================================================================
|
||||
|
||||
// HandleSuccess 统一处理成功响应
|
||||
func (bc *BaseController) HandleSuccess(c *gin.Context, message string, data interface{}) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
@@ -82,6 +102,10 @@ func (bc *BaseController) HandleCreated(c *gin.Context, message string, data int
|
||||
})
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 辅助方法
|
||||
// ============================================================================
|
||||
|
||||
// ValidateRequired 验证必填字段
|
||||
func (bc *BaseController) ValidateRequired(c *gin.Context, fields map[string]interface{}) bool {
|
||||
for fieldName, fieldValue := range fields {
|
||||
|
||||
Reference in New Issue
Block a user