mirror of
https://github.com/criyle/go-judge.git
synced 2025-11-04 14:50:02 +08:00
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
// Command executorserver will starts a http server that receives command to run
|
|
// programs inside a sandbox.
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/criyle/go-judge/pkg/envexec"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
var (
|
|
addr = flag.String("http", ":5050", "specifies the http binding address")
|
|
parallism = flag.Int("parallism", 4, "control the # of concurrency execution")
|
|
tmpFsParam = flag.String("tmpfs", "size=16m,nr_inodes=4k", "tmpfs mount data (only for default mount with no mount.yaml)")
|
|
dir = flag.String("dir", "", "specifies directory to store file upload / download (in memory by default)")
|
|
silent = flag.Bool("silent", false, "do not print logs")
|
|
netShare = flag.Bool("net", false, "do not unshare net namespace with host")
|
|
mountConf = flag.String("mount", "mount.yaml", "specifics mount configuration file")
|
|
|
|
envPool envexec.EnvironmentPool
|
|
|
|
fs fileStore
|
|
|
|
printLog = log.Println
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
if *dir == "" {
|
|
fs = newFileMemoryStore()
|
|
} else {
|
|
os.MkdirAll(*dir, 0755)
|
|
fs = newFileLocalStore(*dir)
|
|
}
|
|
if *silent {
|
|
printLog = func(v ...interface{}) {}
|
|
}
|
|
|
|
initEnvPool()
|
|
|
|
printLog("Starting worker with parallism", *parallism)
|
|
startWorkers()
|
|
|
|
var r *gin.Engine
|
|
if *silent {
|
|
gin.SetMode(gin.ReleaseMode)
|
|
r = gin.New()
|
|
r.Use(gin.Recovery())
|
|
} else {
|
|
r = gin.Default()
|
|
}
|
|
r.GET("/file", fileGet)
|
|
r.POST("/file", filePost)
|
|
r.GET("/file/:fid", fileIDGet)
|
|
r.DELETE("/file/:fid", fileIDDelete)
|
|
r.POST("/run", handleRun)
|
|
|
|
r.GET("/ws", handleWS)
|
|
|
|
printLog("Starting http server at", *addr)
|
|
r.Run(*addr)
|
|
}
|