1. 增加新类型中继设备
2. 优化代码
This commit is contained in:
41
internal/controller/response.go
Normal file
41
internal/controller/response.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Package controller 提供控制器层的公共功能
|
||||
// 包含公共响应结构体和处理函数等
|
||||
package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// APIResponse 通用API响应结构体
|
||||
type APIResponse struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
// SuccessResponseData 成功响应数据结构体
|
||||
type SuccessResponseData struct {
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
// sendSuccessResponse 发送成功响应的公共函数
|
||||
func SendSuccessResponse(ctx *gin.Context, message string, data interface{}) {
|
||||
response := APIResponse{
|
||||
Code: http.StatusOK,
|
||||
Message: message,
|
||||
Data: data,
|
||||
}
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
// sendErrorResponse 发送错误响应的公共函数
|
||||
func SendErrorResponse(ctx *gin.Context, code int, message string) {
|
||||
response := APIResponse{
|
||||
Code: code,
|
||||
Message: message,
|
||||
}
|
||||
ctx.JSON(code, response)
|
||||
}
|
||||
Reference in New Issue
Block a user