API 參考
Gin 伺服器提供的上傳與沙箱執行 HTTP 端點。
端點
POST /upload
上傳並儲存腳本,回傳版本時間戳。
Request body
成功回應
{
"path": "math/add",
"language": "python",
"version": 1739000000
}
錯誤
POST /run/*targetPath
從 Redis 載入程式碼並在沙箱執行。路徑參數為 /run/ 之後的腳本 path。
Query parameters
Request body
Body 內的 code / language 會被 Redis metadata 覆寫。
成功(非串流)
{
"data": 8,
"type": "number"
}
錯誤
POST /run-now
不經 Redis 直接執行。
Request body
錯誤
回應 type
SSE 格式
stream: true 時每筆事件為:
data: {"event":"log","data":"0","type":"text"}
data: {"event":"result","data":"done","type":"string"}
標頭:Content-Type: text/event-stream、Cache-Control: no-cache、Connection: keep-alive。
支援語言
範例
上傳:
curl -X POST http://localhost:8080/upload \
-H "Content-Type: application/json" \
-d '{"path":"math/add","language":"python","code":"return event.get(\"a\", 0) + event.get(\"b\", 0)"}'
執行最新版:
curl -X POST http://localhost:8080/run/math/add \
-H "Content-Type: application/json" \
-d '{"input":"{\"a\": 3, \"b\": 5}"}'
Run-now 串流:
curl -X POST http://localhost:8080/run-now \
-H "Content-Type: application/json" \
-d '{"language":"python","code":"return 1","input":"{}","stream":true}'
相關頁面