run.go 564 B

12345678910111213141516171819202122
  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. default:
  16. c.JSON(400, types.ErrorResponse(-400, "unsupported language"))
  17. }
  18. })
  19. }