feat: 多班级版班级管理系统 v2.0
技术栈:Go (Gin + GORM) + PHP + MySQL 5.7 + Redis 主要功能: - 多班级完全隔离(class_id 贯穿全系统) - 后端 Go Gin(端口 56789),Nginx 反代 - 超级管理员独立登录(env 配置,默认账密 admin/Admin123) - bcrypt 密码加密(无 PASSWORD_SALT) - 科任老师/课代表新角色 - 课代表作业管理页面 - 排行榜分项排行(操行分/考勤/作业) - 角色加减分上下限由班主任配置 - 家长改密功能(可开关) - 班级角色按需开关 - 宿舍号格式:南0-000 - 周度/月度重置功能 - MySQL 5.7 兼容 - 43 轮代码审查 + 全部修复 开发者: Canglan 版权归属: Sea Network Technology Studio 许可证: Apache License 2.0
This commit is contained in:
106
backend-go/pkg/response/response.go
Normal file
106
backend-go/pkg/response/response.go
Normal file
@@ -0,0 +1,106 @@
|
||||
// ===========================================
|
||||
// 多班级版班级管理系统 - Go 后端
|
||||
//
|
||||
// 开发者: Canglan
|
||||
// 联系方式: admin@sea-studio.top
|
||||
// 版权归属: Sea Network Technology Studio
|
||||
// 许可证: Apache License 2.0
|
||||
//
|
||||
// 版权所有 © Sea Network Technology Studio
|
||||
// ===========================================
|
||||
|
||||
package response
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Response 统一响应结构体
|
||||
type Response struct {
|
||||
Success bool `json:"success"`
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
// PageData 分页响应数据
|
||||
type PageData struct {
|
||||
Items interface{} `json:"items"`
|
||||
Total int64 `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
TotalPages int `json:"total_pages"`
|
||||
}
|
||||
|
||||
// JSON 统一 JSON 响应
|
||||
func JSON(c *gin.Context, httpCode int, success bool, code int, message string, data interface{}) {
|
||||
c.JSON(httpCode, Response{
|
||||
Success: success,
|
||||
Code: code,
|
||||
Message: message,
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
// Success 成功响应 (200)
|
||||
func Success(c *gin.Context, data interface{}, message string) {
|
||||
JSON(c, http.StatusOK, true, 200, message, data)
|
||||
}
|
||||
|
||||
// SuccessWithMessage 成功响应(仅消息)
|
||||
func SuccessWithMessage(c *gin.Context, message string) {
|
||||
JSON(c, http.StatusOK, true, 200, message, nil)
|
||||
}
|
||||
|
||||
// Created 创建成功响应 (201)
|
||||
func Created(c *gin.Context, data interface{}, message string) {
|
||||
JSON(c, http.StatusCreated, true, 201, message, data)
|
||||
}
|
||||
|
||||
// BadRequest 参数错误 (400)
|
||||
func BadRequest(c *gin.Context, message string) {
|
||||
JSON(c, http.StatusBadRequest, false, 400, message, nil)
|
||||
}
|
||||
|
||||
// Unauthorized 未授权 (401)
|
||||
func Unauthorized(c *gin.Context, message string) {
|
||||
JSON(c, http.StatusUnauthorized, false, 401, message, nil)
|
||||
}
|
||||
|
||||
// Forbidden 禁止访问 (403)
|
||||
func Forbidden(c *gin.Context, message string) {
|
||||
JSON(c, http.StatusForbidden, false, 403, message, nil)
|
||||
}
|
||||
|
||||
// NotFound 资源不存在 (404)
|
||||
func NotFound(c *gin.Context, message string) {
|
||||
JSON(c, http.StatusNotFound, false, 404, message, nil)
|
||||
}
|
||||
|
||||
// Conflict 冲突 (409)
|
||||
func Conflict(c *gin.Context, message string) {
|
||||
JSON(c, http.StatusConflict, false, 409, message, nil)
|
||||
}
|
||||
|
||||
// InternalError 服务器内部错误 (500)
|
||||
func InternalError(c *gin.Context, message string) {
|
||||
JSON(c, http.StatusInternalServerError, false, 500, message, nil)
|
||||
}
|
||||
|
||||
// Paginated 分页成功响应
|
||||
func Paginated(c *gin.Context, items interface{}, total int64, page, pageSize int) {
|
||||
totalPages := int(total) / pageSize
|
||||
if int(total)%pageSize > 0 {
|
||||
totalPages++
|
||||
}
|
||||
|
||||
Success(c, PageData{
|
||||
Items: items,
|
||||
Total: total,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
TotalPages: totalPages,
|
||||
}, "操作成功")
|
||||
}
|
||||
Reference in New Issue
Block a user