mirror of
https://github.com/criyle/go-judge.git
synced 2025-11-04 14:50:02 +08:00
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"runtime"
|
|
|
|
"github.com/criyle/go-judge/cmd/executorserver/model"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func handleRun(c *gin.Context) {
|
|
var req model.Request
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.Error(err)
|
|
c.AbortWithStatusJSON(http.StatusBadRequest, err.Error())
|
|
return
|
|
}
|
|
|
|
if len(req.Cmd) == 0 {
|
|
c.AbortWithStatusJSON(http.StatusBadRequest, "no cmd provided")
|
|
return
|
|
}
|
|
r, err := model.ConvertRequest(&req, *srcPrefix)
|
|
if err != nil {
|
|
c.Error(err)
|
|
c.AbortWithStatusJSON(http.StatusBadRequest, err.Error())
|
|
return
|
|
}
|
|
rt := <-work.Submit(c.Request.Context(), r)
|
|
execObserve(rt)
|
|
if rt.Error != nil {
|
|
c.Error(rt.Error)
|
|
c.AbortWithStatusJSON(http.StatusInternalServerError, rt.Error.Error())
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, model.ConvertResponse(rt).Results)
|
|
}
|
|
|
|
func handleVersion(c *gin.Context) {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"buildVersion": Version,
|
|
"goVersion": runtime.Version(),
|
|
"platform": runtime.GOARCH,
|
|
"os": runtime.GOOS,
|
|
})
|
|
}
|