package main import ( "net/http" "strconv" ) func handleListRuns(executor *Executor) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { dagName := r.URL.Query().Get("dag") limit, _ := strconv.Atoi(r.URL.Query().Get("limit")) offset, _ := strconv.Atoi(r.URL.Query().Get("offset")) if limit <= 0 || limit > 100 { limit = 20 } if offset < 0 { offset = 0 } runs, total, err := executor.store.ListRuns(dagName, limit, offset) if err != nil { writeError(w, http.StatusInternalServerError, err.Error()) return } writeJSON(w, http.StatusOK, map[string]interface{}{ "runs": runs, "total": total, "limit": limit, "offset": offset, }) } } func handleGetRun(executor *Executor) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { id := r.PathValue("id") run, err := executor.store.GetRun(id) if err != nil { writeError(w, http.StatusInternalServerError, err.Error()) return } if run == nil { writeError(w, http.StatusNotFound, "run not found") return } steps, err := executor.store.ListStepResults(id) if err != nil { writeError(w, http.StatusInternalServerError, err.Error()) return } writeJSON(w, http.StatusOK, map[string]interface{}{ "run": run, "steps": steps, }) } }