run.go 629 B

123456789101112131415161718192021222324
  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. }) {
  12. switch req.Language {
  13. case "python3":
  14. c.JSON(200, service.RunPython3Code(req.Code))
  15. case "nodejs":
  16. c.JSON(200, service.RunNodeJsCode(req.Code))
  17. default:
  18. c.JSON(400, types.ErrorResponse(-400, "unsupported language"))
  19. }
  20. })
  21. }