-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.go
More file actions
56 lines (46 loc) · 1.39 KB
/
Copy pathcode.go
File metadata and controls
56 lines (46 loc) · 1.39 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// manifold/code.go
package main
import (
"log"
"net/http"
"strings"
agentspkg "manifold/internal/agents"
configpkg "manifold/internal/config"
"github.com/labstack/echo/v4"
)
// evaluateCodeHandler is the HTTP handler that dispatches based on language.
func evaluateCodeHandler(c echo.Context) error {
var req agentspkg.CodeEvalRequest
if err := c.Bind(&req); err != nil {
log.Printf("Received language: [%s]", req.Language)
return c.JSON(http.StatusBadRequest, agentspkg.CodeEvalResponse{
Error: "Invalid request body: " + err.Error(),
})
}
// Trim and lower-case to avoid trailing spaces, etc.
lang := strings.ToLower(strings.TrimSpace(req.Language))
log.Printf("Received language: [%s]", lang)
var (
resp *agentspkg.CodeEvalResponse
err error
)
cfg, _ := c.Get("config").(*configpkg.Config)
switch lang {
case "python":
resp, err = agentspkg.RunPythonInContainer(cfg, req.Code, req.Dependencies)
case "go":
resp, err = agentspkg.RunGoInContainer(cfg, req.Code, req.Dependencies)
case "javascript":
resp, err = agentspkg.RunNodeInContainer(cfg, req.Code, req.Dependencies)
default:
return c.JSON(http.StatusBadRequest, agentspkg.CodeEvalResponse{
Error: "Unsupported language: " + req.Language,
})
}
if err != nil {
return c.JSON(http.StatusInternalServerError, agentspkg.CodeEvalResponse{
Error: err.Error(),
})
}
return c.JSON(http.StatusOK, resp)
}