aboutsummaryrefslogtreecommitdiffhomepage
path: root/worker/swift/handlers.go
blob: 4cb999997dfba0669345e676cc1ae599f0d92c32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 handleExec(c echo.Context) error {
	var req execRequestData
	if err := c.Bind(&req); err != nil {
		return newBadRequestError(err)
	}
	if err := req.validate(); err != nil {
		return newBadRequestError(err)
	}

	res := doExec(
		c.Request().Context(),
		req.Code,
		req.CodeHash,
		req.Stdin,
		req.maxDuration(),
	)

	return c.JSON(http.StatusOK, res)
}