router.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/langgenius/dify-sandbox/internal/middleware"
  5. "github.com/langgenius/dify-sandbox/internal/static"
  6. "net/http"
  7. )
  8. func Setup(Router *gin.Engine) {
  9. PublicGroup := Router.Group("")
  10. PrivateGroup := Router.Group("/v1/sandbox/")
  11. PrivateGroup.Use(middleware.Auth())
  12. {
  13. // health check
  14. PublicGroup.GET("/health", func(c *gin.Context) {
  15. c.JSON(http.StatusOK, "ok")
  16. })
  17. }
  18. InitRunRouter(PrivateGroup)
  19. InitDependencyRouter(PrivateGroup)
  20. }
  21. func InitDependencyRouter(Router *gin.RouterGroup) {
  22. dependencyRouter := Router.Group("dependencies")
  23. {
  24. dependencyRouter.GET("", GetDependencies)
  25. dependencyRouter.POST("update", UpdateDependencies)
  26. dependencyRouter.GET("refresh", RefreshDependencies)
  27. }
  28. }
  29. func InitRunRouter(Router *gin.RouterGroup) {
  30. runRouter := Router.Group("")
  31. {
  32. runRouter.POST(
  33. "run",
  34. middleware.MaxRequest(static.GetDifySandboxGlobalConfigurations().MaxRequests),
  35. middleware.MaxWorker(static.GetDifySandboxGlobalConfigurations().MaxWorkers),
  36. RunSandboxController,
  37. )
  38. }
  39. }