Skip to content

Commit

Permalink
feat: add support for golang & rust
Browse files Browse the repository at this point in the history
  • Loading branch information
seo-rii committed Jan 1, 2022
1 parent 6cf9005 commit d809e06
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 60 deletions.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ RUN java -version
RUN apk add rust
RUN rustc --version

# Install Go
RUN apk add go
RUN mkdir /tmp/gocache
RUN chmod 777 /tmp/gocache
ENV GOROOT /usr/lib/go
ENV GOCACHE /tmp/gocache
ENV PATH /go/bin:$PATH

# Copy files & Install requirements
RUN addgroup execute
Expand Down
93 changes: 34 additions & 59 deletions res/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,23 @@
CP: 'Compiling',
RUN: 'Running',
}
const supportedLanguages = [
'C',
'CPP',
'PYTHON3',
'PYPY3',
'JAVA',
'RUST',
'GO',
]
const ext = {
PYTHON3: 'py',
PYPY3: 'py',
CPP: 'cpp',
C: 'c',
JAVA: 'java',
RUST: 'rs',
GO: 'go',
}

const exampleCode = {
Expand Down Expand Up @@ -202,6 +212,17 @@
};
println!("{}", number_a + number_b);
}`,
GO: `package main
import (
\t"fmt"
)
func main() {
\tvar a, b int
\tfmt.Scanf("%d %d", &a, &b)
\tfmt.Println(a+b)
}`,
}

Expand Down Expand Up @@ -358,7 +379,7 @@ <h4>State</h4>
],
},
timeLimit: 2000,
memoryLimit: 100,
memoryLimit: 1000,
}),
})
}
Expand All @@ -373,6 +394,17 @@ <h4>State</h4>
}

document.addEventListener('DOMContentLoaded', () => {
for (let i of supportedLanguages) {
document.getElementById('supportedLang').innerHTML += `<li
class="mdc-list-item ripple"
aria-selected="false"
data-value="${i}"
role="option"
>
<span class="mdc-list-item__ripple"></span>
<span class="mdc-list-item__text">${i}</span>
</li>`
}
setInterval(() => {
if (document.documentElement.scrollTop)
document
Expand Down Expand Up @@ -482,64 +514,7 @@ <h3>Problem</h3>
<div
class="mdc-select__menu mdc-menu mdc-menu-surface mdc-menu-surface--fullwidth"
>
<ul class="mdc-list">
<li
class="mdc-list-item ripple"
aria-selected="false"
data-value="C"
role="option"
>
<span class="mdc-list-item__ripple"></span>
<span class="mdc-list-item__text"> C </span>
</li>
<li
class="mdc-list-item ripple"
aria-selected="false"
data-value="CPP"
role="option"
>
<span class="mdc-list-item__ripple"></span>
<span class="mdc-list-item__text"> CPP </span>
</li>
<li
class="mdc-list-item ripple"
aria-selected="false"
data-value="PYTHON3"
role="option"
>
<span class="mdc-list-item__ripple"></span>
<span class="mdc-list-item__text">
PYTHON3
</span>
</li>
<li
class="mdc-list-item ripple"
aria-selected="false"
data-value="PYPY3"
role="option"
>
<span class="mdc-list-item__ripple"></span>
<span class="mdc-list-item__text"> PYPY3 </span>
</li>
<li
class="mdc-list-item ripple"
aria-selected="false"
data-value="JAVA"
role="option"
>
<span class="mdc-list-item__ripple"></span>
<span class="mdc-list-item__text"> JAVA </span>
</li>
<li
class="mdc-list-item ripple"
aria-selected="false"
data-value="RUST"
role="option"
>
<span class="mdc-list-item__ripple"></span>
<span class="mdc-list-item__text"> RUST </span>
</li>
</ul>
<ul class="mdc-list" id="supportedLang"></ul>
</div>
</div>
<label
Expand Down
16 changes: 16 additions & 0 deletions src/runner/golang.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { JudgeRequest } from '../types/request'
import { execute, getLimitString } from './util'
import commonJudge from './common'

export default function (data: JudgeRequest) {
return commonJudge(
data,
(path) =>
execute(
`p-${data.uid}`,
getLimitString({ cpuLimit: 50 }, `go build ${path}/Main.go`),
{ cwd: path }
),
(path) => path + '/Main'
)
}
4 changes: 3 additions & 1 deletion src/runner/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
CommonDataSet,
JudgeRequest,
JudgeSourceType,
JudgeType,
Expand All @@ -14,6 +13,7 @@ import judgePython3 from './python3'
import judgePypy3 from './pypy3'
import judgeJava from './java'
import judgeRust from './rust'
import judgeGo from './golang'

export default function (data: JudgeRequest): Promise<JudgeResult> {
switch (data.judgeType) {
Expand All @@ -39,6 +39,8 @@ export default function (data: JudgeRequest): Promise<JudgeResult> {
return judgeJava(data)
case JudgeSourceType.RUST:
return judgeRust(data)
case JudgeSourceType.GO:
return judgeGo(data)
}
return Promise.resolve({
uid: data.uid,
Expand Down

0 comments on commit d809e06

Please sign in to comment.