https://github.com/criyle/go-judge-demo
Demo front-end and back-end for a online judge implementation using go-judge
https://github.com/criyle/go-judge-demo
go-judge online-judge sandbox
Last synced: 5 months ago
JSON representation
Demo front-end and back-end for a online judge implementation using go-judge
- Host: GitHub
- URL: https://github.com/criyle/go-judge-demo
- Owner: criyle
- License: mit
- Created: 2019-06-24T02:56:20.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-12-30T07:19:06.000Z (6 months ago)
- Last Synced: 2026-01-14T14:49:14.882Z (5 months ago)
- Topics: go-judge, online-judge, sandbox
- Language: Go
- Homepage: https://goj.ac
- Size: 1.44 MB
- Stars: 27
- Watchers: 0
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-judge-demo
A simple demo site for the [go-judge](https://github.com/criyle/go-judge), deployed on M1 Mac Mini docker desktop [site](https://goj.ac).
Components:
- Frontend: Vue 3, Naive UI, monaco editor
- APIGateway: GO
- Backend: GO
- Judger Client: GO
- Dev Server Compiler: Air, Overmind
Tools:
-
-
```bash
go install github.com/air-verse/air@latest
go install github.com/DarthSim/overmind@latest
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
```
## API Gateway
### Interface
- GET /api/submission?id=_id: Query history submissions
- POST /api/submit: Submit judge request
- WS /api/ws/judge: Broadcast judge updates
- WS /api/ws/shell: Interactive shell
- GET /: SPA HTML & JS -> /dist
## Backend
Token-based gRPC
- submission(id)
- submit(request)
- updates(): stream judge updates
- judge(): stream for judge client
- shell(): stream for interactive shell
default ports:
- gRPC: `:5081`
- metrics: `:5082`
## Judge Client
Connect to backend with judge()
- metrics: `:2112`
## Development
```bash
# front end
npm run dev
# apigateway
# demoserver
# judger
overmind start -f Procfile.dev
# mongoDB
docker run -p 27017:27017 mongo
# exec server in go-judge directory
air
```
## Docker build
```bash
# front end and api server
docker build -t apigateway -f Dockerfile.apigateway .
docker build -t demoserver -f Dockerfile.demoserver .
# judge client and go-judge executor
docker build -t judger -f Dockerfile.judger .
docker build -t judger_exec -f Dockerfile.exec .
```
## Docker run
```bash
# mongo database
docker run --name mongo -d -p 27017:27017 mongo
# demo server
docker run --name demo --link mongo -d -e MONGODB_URI=mongodb://mongo:27017/test -p 5081:5081 -p 5082:5082 demoserver
# api gateway
docker run --name apigateway --link demo -d -e DEMO_SERVER=demo:5081 -p 5000:5000 apigateway
# go-judge executor service
docker run --name exec -d --privileged -e ES_ENABLE_GRPC=1 -e ES_ENABLE_METRICS=1 -e ES_ENABLE_DEBUG=1 -p 5052:5052 -p 5051:5051 -p 5050:5050 judger_exec
# judger client
docker run --name judger --link exec --link demo -d -e DEMO_SERVER=demo:5081 -e EXEC_SERVER=exec:5051 -p 2112:2112 judger
```
## Data Model
Language:
``` json
{
"name": "c++",
"sourceFileName": "a.cc",
"compileCmd": "g++ -o a a.cc",
"executables": [ "a" ],
"runCmd": "a",
}
```
Result:
``` json
{
"_id": "primary key",
"language": "",
"source": "",
"date": "",
"status": "",
"totalTime": "total time",
"maxMemory": "max memory",
"results": [
{
"time": "",
"memory": "",
"stdin": "",
"stdout": "",
"stderr": "",
"log": "",
},
],
}
```
### POST /api/submit
Request:
```json
{
"language": "",
"source": "",
}
```
Response:
```json
{
"_id": "<_id>"
}
```
### Client WS
S -> C:
``` json
{
"id": "",
"status": "",
"date": "",
"language": "language name",
"results": "results[]"
}
```
### Judger WS
Include `Authorization: Token token` in the HTTP Header when call for upgrade.
J -> S:
Progress:
``` json
{
"id": "",
"type": "progress",
"status": "",
"date": "",
"language": "language name",
}
```
Finish:
``` json
{
"id": "",
"type": "finish",
"status": "",
"date": "",
"language": "language name",
"results": [ "result" ],
}
```
S -> J:
``` json
{
"id": "",
"language": "",
"source": "source",
}
```