feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers

This commit is contained in:
2026-04-02 11:19:50 +08:00
parent e59a77bc49
commit dcc1f186f8
298 changed files with 62603 additions and 0 deletions

50
pkg/response/response.go Normal file
View File

@@ -0,0 +1,50 @@
package response
import (
"net/http"
"github.com/gin-gonic/gin"
)
// Response 统一响应结构
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
// Success 成功响应
func Success(c *gin.Context, data interface{}) {
c.JSON(http.StatusOK, Response{
Code: 0,
Message: "success",
Data: data,
})
}
// Error 错误响应
func Error(c *gin.Context, httpStatus int, message string, err error) {
if err != nil {
// 在开发环境下返回详细错误信息
if gin.Mode() == gin.DebugMode {
c.JSON(httpStatus, Response{
Code: httpStatus,
Message: message,
Data: err.Error(),
})
return
}
}
c.JSON(httpStatus, Response{
Code: httpStatus,
Message: message,
})
}
// ErrorWithCode 错误响应(带自定义错误码)
func ErrorWithCode(c *gin.Context, code int, message string) {
c.JSON(http.StatusOK, Response{
Code: code,
Message: message,
})
}