From 39167ded7c2fc3fb50cbd24dc6b0192648ebfc54 Mon Sep 17 00:00:00 2001 From: Microvenator Date: Tue, 26 Aug 2025 18:49:41 +0300 Subject: [PATCH] Practice for golang --- golang/Dockerfile | 6 +++- golang/practice/run-practice.sh | 64 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 golang/practice/run-practice.sh diff --git a/golang/Dockerfile b/golang/Dockerfile index 41a6176..40bf4ce 100644 --- a/golang/Dockerfile +++ b/golang/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.22.5 +FROM golang:1.24 LABEL ru.senjun.image.authors="Shipilov Dmitry" WORKDIR /home/code_runner @@ -11,6 +11,10 @@ COPY task/run-task.sh /home/code_runner/task RUN mkdir /home/code_runner/playground COPY playground/run-playground.sh /home/code_runner/playground +# Directory for practice +RUN mkdir /home/code_runner/practice +COPY practice/run-practice.sh /home/code_runner/practice + RUN mkdir -p task/user-code && cd task/user-code && go mod init senjun/user/user-code # Change access write for code_runner home directory to root recursively diff --git a/golang/practice/run-practice.sh b/golang/practice/run-practice.sh new file mode 100644 index 0000000..1974798 --- /dev/null +++ b/golang/practice/run-practice.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +# parse flags - single letters prefixed with hyphen before each argument +# example: sh run.sh -f task +# column after option means required argument +while getopts f:p:o:rt opt +do + case "${opt}" in + f) project=${OPTARG} + ;; + o) user_options="${OPTARG}" + ;; + p) main_path=${OPTARG} + ;; + r) run=${OPTARG} + ;; + t) test=${OPTARG} + ;; + \?) echo "Invalid option" >&2 + exit + ;; + esac +done + +# prepare project +f="$(basename -- $project)" +cd /home/code_runner/practice/$f/cmd + +# we call gofmt to prevent compiler errors: +# go compiler treats formatting errors as compilation errors! + +# TODO: format go code in online IDE to show user the right way +# timeout 5s gofmt -s -w . + +if [ ${run+x} ]; then + # run cpp project + # TODO which name for project should use here? + + if ! ( timeout 10s go run . ); then + echo "Code execution timeout" + echo user_solution_error_f936a25e + exit + fi + + echo user_code_ok_f936a25e + echo user_solution_ok_f936a25e + exit +fi + +# e.g: sh run.sh -f dir_name -t +if [ ${test+x} ]; then + echo user_code_ok_f936a25e + if ! ( timeout 10s go test . ); then + echo "Tests execution timeout" + echo tests_cases_error_f936a25e + exit + fi + + echo user_solution_ok_f936a25e + exit +fi + +# Never goes here +echo "Never should go here!" \ No newline at end of file