aboutsummaryrefslogtreecommitdiffhomepage
path: root/worker/handlers.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-02 19:16:58 +0900
committernsfisis <nsfisis@gmail.com>2024-08-03 18:56:00 +0900
commitf70d6eed9f2c519aed030c9dbda99ed0435991a0 (patch)
tree2c4e95392c88fcdbccafe62e42b651f4fbde0491 /worker/handlers.go
parentdb06c9332776b41b3fef537f9e6d76d38f0463b3 (diff)
downloadiosdc-japan-2024-albatross-f70d6eed9f2c519aed030c9dbda99ed0435991a0.tar.gz
iosdc-japan-2024-albatross-f70d6eed9f2c519aed030c9dbda99ed0435991a0.tar.zst
iosdc-japan-2024-albatross-f70d6eed9f2c519aed030c9dbda99ed0435991a0.zip
feat: implement worker
Diffstat (limited to 'worker/handlers.go')
-rw-r--r--worker/handlers.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/worker/handlers.go b/worker/handlers.go
new file mode 100644
index 0000000..e7ceef6
--- /dev/null
+++ b/worker/handlers.go
@@ -0,0 +1,67 @@
+package main
+
+import (
+ "fmt"
+ "net/http"
+
+ "github.com/labstack/echo/v4"
+)
+
+func newBadRequestError(err error) *echo.HTTPError {
+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid request: %s", err.Error()))
+}
+
+func handleSwiftCompile(c echo.Context) error {
+ var req swiftCompileRequestData
+ if err := c.Bind(&req); err != nil {
+ return newBadRequestError(err)
+ }
+ if err := req.validate(); err != nil {
+ return newBadRequestError(err)
+ }
+
+ res := execSwiftCompile(
+ c.Request().Context(),
+ req.Code,
+ req.maxDuration(),
+ )
+
+ return c.JSON(http.StatusOK, res)
+}
+
+func handleWasmCompile(c echo.Context) error {
+ var req wasmCompileRequestData
+ if err := c.Bind(&req); err != nil {
+ return newBadRequestError(err)
+ }
+ if err := req.validate(); err != nil {
+ return newBadRequestError(err)
+ }
+
+ res := execWasmCompile(
+ c.Request().Context(),
+ req.Code,
+ req.maxDuration(),
+ )
+
+ return c.JSON(http.StatusOK, res)
+}
+
+func handleTestRun(c echo.Context) error {
+ var req testRunRequestData
+ if err := c.Bind(&req); err != nil {
+ return newBadRequestError(err)
+ }
+ if err := req.validate(); err != nil {
+ return newBadRequestError(err)
+ }
+
+ res := execTestRun(
+ c.Request().Context(),
+ req.Code,
+ req.Stdin,
+ req.maxDuration(),
+ )
+
+ return c.JSON(http.StatusOK, res)
+}