run.go 705 B

12345678910111213141516171819202122232425
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/langgenius/dify-sandbox/internal/service"
  5. "github.com/langgenius/dify-sandbox/internal/types"
  6. )
  7. func RunSandboxController(c *gin.Context) {
  8. BindRequest(c, func(req struct {
  9. Language string `json:"language" form:"language" binding:"required"`
  10. Code string `json:"code" form:"code" binding:"required"`
  11. Preload string `json:"preload" form:"preload"`
  12. }) {
  13. switch req.Language {
  14. case "python3":
  15. c.JSON(200, service.RunPython3Code(req.Code, req.Preload))
  16. case "nodejs":
  17. c.JSON(200, service.RunNodeJsCode(req.Code, req.Preload))
  18. default:
  19. c.JSON(400, types.ErrorResponse(-400, "unsupported language"))
  20. }
  21. })
  22. }