40 lines
682 B
Go
40 lines
682 B
Go
package pkg
|
||
|
||
import (
|
||
"excel_export/pkg/e"
|
||
"fmt"
|
||
"github.com/gin-gonic/gin"
|
||
"net/http"
|
||
)
|
||
|
||
type Gin struct {
|
||
C *gin.Context
|
||
}
|
||
|
||
type ResponseStruct struct {
|
||
Code int `json:"code"`
|
||
Msg string `json:"msg"`
|
||
Data interface{} `json:"data"`
|
||
}
|
||
|
||
func (g *Gin) Success(data interface{}) {
|
||
g.C.JSON(http.StatusOK, ResponseStruct{
|
||
Code: e.SUCCESS,
|
||
Msg: e.GetMsg(e.SUCCESS),
|
||
Data: data,
|
||
})
|
||
}
|
||
|
||
func (g *Gin) Error(code int, extraInfo string) {
|
||
g.C.AbortWithStatusJSON(http.StatusBadRequest, ResponseStruct{
|
||
Code: code,
|
||
Msg: fmt.Sprintf("%s:%s", e.GetMsg(code), extraInfo),
|
||
Data: "",
|
||
})
|
||
}
|
||
|
||
func Response(c *gin.Context) *Gin {
|
||
r := Gin{C: c}
|
||
return &r
|
||
}
|