36 lines
605 B
Go
36 lines
605 B
Go
package common
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Response[T any] struct {
|
|
Code int `json:"code" example:"0"`
|
|
Msg string `json:"msg" example:"success"`
|
|
Data T `json:"data,omitempty"`
|
|
}
|
|
|
|
func Succ(c *gin.Context, data interface{}) {
|
|
c.JSON(http.StatusOK, Response[interface{}]{
|
|
Code: 0,
|
|
Msg: "success",
|
|
Data: data,
|
|
})
|
|
}
|
|
|
|
func Ok(c *gin.Context, msg string) {
|
|
c.JSON(http.StatusOK, Response[interface{}]{
|
|
Code: 0,
|
|
Msg: msg,
|
|
})
|
|
}
|
|
|
|
func Fail(c *gin.Context, msg string) {
|
|
c.JSON(http.StatusBadRequest, Response[interface{}]{
|
|
Code: -1,
|
|
Msg: msg,
|
|
})
|
|
}
|