run.go 772 B

123456789101112131415161718192021222324252627282930313233
  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/static"
  6. "github.com/langgenius/dify-sandbox/internal/types"
  7. )
  8. var (
  9. queue chan bool
  10. )
  11. func InitSandBoxQueue() {
  12. if queue == nil {
  13. queue = make(chan bool, static.GetCoshubGlobalConfigurations().MaxWorkers)
  14. }
  15. }
  16. func RunSandboxController(c *gin.Context) {
  17. BindRequest(c, func(req struct {
  18. Language string `json:"language" form:"language" binding:"required"`
  19. Code string `json:"code" form:"code" binding:"required"`
  20. }) {
  21. switch req.Language {
  22. case "python3":
  23. c.JSON(200, service.RunPython3Code(req.Code))
  24. default:
  25. c.JSON(400, types.ErrorResponse(-400, "unsupported language"))
  26. }
  27. })
  28. }