package routers import ( "github.com/gin-gonic/gin" "kpt.xdmy/apiserver/model" "kpt.xdmy/apiserver/model/http" "kpt.xdmy/apiserver/service" ) var ( svc *service.Service ) func Init(s *service.Service) { svc = s } func eJSON(c *gin.Context, rp *http.Response, e error) { if rp == nil { rp = &http.Response{} } if e != nil { rp.Message = e.Error() rp.Success = false if rp.Code == 0 { rp.Code = 400 } } if e == nil { rp.Success = true rp.Code = 200 } c.JSON(rp.Code, &rp) return } func Bind(c *gin.Context, req model.Request) bool { if err := c.ShouldBind(req); err != nil { rp := &http.Response{ Code: 500, Message: err.Error(), } eJSON(c, rp, nil) return false } return true }