excel-export/pkg/response.go

40 lines
682 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}