service/library/middleware/json_encoder.go

25 lines
409 B
Go

package middleware
import (
"net/http"
"service/api/base"
"service/api/consts"
"github.com/gin-gonic/gin"
)
func JsonEncoder() gin.HandlerFunc {
return func(ctx *gin.Context) {
if data, exists := ctx.Get("pending_data"); exists {
ctx.JSON(http.StatusOK, base.BaseResponse{
Ret: consts.RetCodeSuccess,
ErrCode: consts.ErrorCodeSuccess,
Data: data,
})
}
ctx.Next()
}
}