Skip to content

Commit a3de075

Browse files
committed
Add support for golang
1 parent 11d5e20 commit a3de075

File tree

8 files changed

+67
-0
lines changed

8 files changed

+67
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Currently we have following images -
2222
- [c](containers/c)
2323
- [cpp](containers/cpp)
2424
- [c#](containers/csharp)
25+
- [golang](containers/golang)
2526
- [java8](containers/java8)
2627
- [nodejs6](containers/nodejs6)
2728
- [nodejs](containers/nodejs8)

containers/golang/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM frolvlad/alpine-go
2+
3+
RUN apk add --no-cache bash
4+
5+
COPY ./compile.sh /bin/compile.sh
6+
COPY ./run.sh /bin/run.sh
7+
8+
RUN chmod 777 /bin/compile.sh; \
9+
chmod 777 /bin/run.sh

containers/golang/compile.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#!/usr/bin/env bash

containers/golang/run.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
chmod 777 program.go
4+
go run program.go < run.stdin 1> run.stdout 2> run.stderr

test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
bash tests/csharp/test_worker.sh
1313
}
1414

15+
@test "test golang" {
16+
bash tests/golang/test_worker.sh
17+
}
18+
1519
@test "test java8" {
1620
bash tests/java8/test_worker.sh
1721
}

tests/golang/program.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main;
2+
3+
import "fmt";
4+
5+
func main() {
6+
var input string
7+
fmt.Scanf("%s", &input)
8+
fmt.Println("Hello " + input)
9+
}

tests/golang/run.stdin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
World

tests/golang/test_worker.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
pushd $(dirname "$0")
3+
DIR=$(pwd)
4+
RUNBOX="${DIR}/runbox"
5+
6+
echo $RUNBOX
7+
# Create runbox
8+
mkdir -p $RUNBOX
9+
10+
# Copy source to runbox
11+
cp $DIR/program.go $RUNBOX/program.go
12+
cp $DIR/run.stdin $RUNBOX/run.stdin
13+
14+
# Test Compile
15+
docker run \
16+
--cpus="1" \
17+
--memory="100m" \
18+
--ulimit nofile=64:64 \
19+
--rm \
20+
--read-only \
21+
-v "$RUNBOX":/usr/src/runbox \
22+
-v "$RUNBOX":/tmp \
23+
-w /usr/src/runbox codingblocks/judge-worker-golang \
24+
bash -c "/bin/compile.sh && /bin/run.sh"
25+
26+
ls -lh ${RUNBOX}
27+
28+
expected="Hello World"
29+
actual="$(cat ${RUNBOX}/run.stdout)"
30+
if [ "$expected" == "$actual" ] ;then
31+
:
32+
else
33+
echo "MISMATCH: Expected = $expected; Actual = $actual"
34+
exit 1
35+
fi
36+
37+
# Delete runbox
38+
rm -rf $RUNBOX

0 commit comments

Comments
 (0)