init
This commit is contained in:
30
response/response.go
Normal file
30
response/response.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"energy-management-system/utils/exception"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Data interface{} `json:"data"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
// Result ... 正常业务获得结果
|
||||
func Result(code int, data interface{}, msg string, c *gin.Context) {
|
||||
c.JSON(http.StatusOK, Response{code, data, msg})
|
||||
}
|
||||
|
||||
func Success(c *gin.Context) {
|
||||
SuccessMsg("操作成功", c)
|
||||
}
|
||||
|
||||
func SuccessMsg(message string, c *gin.Context) {
|
||||
Result(exception.SUCCESS, map[string]interface{}{}, message, c)
|
||||
}
|
||||
|
||||
func SuccessData(data interface{}, c *gin.Context) {
|
||||
Result(exception.SUCCESS, data, "操作成功", c)
|
||||
}
|
||||
Reference in New Issue
Block a user