woj-server/internal/e/resp.go
Paul Pan 26a81652b3 feat: another big update
1. add consumer
2. add createVersion
3. add upload
4. fix runner
5. add rejudge

Co-authored-by: cxy004 <cxy004@qq.com>
Co-authored-by: wzt <w.zhongtao@qq.com>
2022-10-23 17:29:35 +08:00

36 lines
731 B
Go

package e
import (
"github.com/WHUPRJ/woj-server/pkg/utils"
"github.com/gin-gonic/gin"
"net/http"
)
type Response struct {
Code int `json:"code"`
Msg string `json:"msg"`
Body interface{} `json:"body"`
}
func Wrap(status Status, body interface{}) interface{} {
return Response{
Code: int(status),
Msg: status.String(),
Body: utils.If(status == Success, body, nil),
}
}
func Pong(c *gin.Context, status Status, body interface{}) {
c.Set("err", status)
c.JSON(http.StatusOK, Wrap(status, body))
}
type Endpoint func(*gin.Context) (Status, interface{})
func PongWrapper(handler Endpoint) func(*gin.Context) {
return func(c *gin.Context) {
status, body := handler(c)
Pong(c, status, body)
}
}