service/library/middleware/json_encoder.go

25 lines
409 B
Go
Raw Permalink Normal View History

2023-12-21 22:17:40 +08:00
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()
}
}