内网服务访问外部第三方 API 的统一网关
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

47 lines
743 B

package utils
import (
"net/http"
"github.com/gin-gonic/gin"
)
type R struct {
Code int `json:"code"`
Data any `json:"data"`
}
func OK(c *gin.Context) {
c.JSON(http.StatusOK, R{
Code: http.StatusOK,
})
}
func OKNoData(c *gin.Context) {
c.JSON(http.StatusNoContent, R{
Code: http.StatusOK,
})
}
func OKWithData(c *gin.Context, obj interface{}) {
c.JSON(http.StatusOK, R{
Code: http.StatusOK,
Data: obj,
})
}
func FailWithData(c *gin.Context, obj interface{}) {
c.JSON(http.StatusOK, R{
Code: http.StatusInternalServerError,
Data: obj,
})
}
func OKWithList(c *gin.Context, total int, obj any) {
c.JSON(http.StatusOK, gin.H{
"code": http.StatusOK,
"data": gin.H{
"total": total,
"list": obj,
},
})
}