(w http.ResponseWriter, r *http.Request)
| 219 | } |
| 220 | |
| 221 | func (s *Server) handleStop(w http.ResponseWriter, r *http.Request) { |
| 222 | var req StopRequest |
| 223 | if err := json.NewDecoder(r.Body).Decode(&req); err != nil { |
| 224 | writeJSONError(w, http.StatusBadRequest, "invalid request body", err.Error()) |
| 225 | return |
| 226 | } |
| 227 | |
| 228 | if req.Path == "" { |
| 229 | writeJSONError(w, http.StatusBadRequest, "path required", nil) |
| 230 | return |
| 231 | } |
| 232 | |
| 233 | expandedPath, err := s.expandPath(req.Path) |
| 234 | if err != nil { |
| 235 | writeJSONError(w, http.StatusBadRequest, fmt.Sprintf("invalid path: %v", err), nil) |
| 236 | return |
| 237 | } |
| 238 | |
| 239 | timeout := req.Timeout |
| 240 | if timeout == 0 { |
| 241 | timeout = 30 |
| 242 | } |
| 243 | ctx, cancel := context.WithTimeout(s.ctx, time.Duration(timeout)*time.Second) |
| 244 | defer cancel() |
| 245 | |
| 246 | db := s.store.FindDB(expandedPath) |
| 247 | if db == nil { |
| 248 | writeJSONError(w, http.StatusInternalServerError, fmt.Sprintf("database not found: %s", expandedPath), nil) |
| 249 | return |
| 250 | } |
| 251 | |
| 252 | status := "stopped" |
| 253 | if !db.IsOpen() { |
| 254 | status = "already_stopped" |
| 255 | } else { |
| 256 | if err := s.store.DisableDB(ctx, expandedPath); err != nil { |
| 257 | writeJSONError(w, http.StatusInternalServerError, err.Error(), nil) |
| 258 | return |
| 259 | } |
| 260 | } |
| 261 | txID, err := s.storeTXID(expandedPath) |
| 262 | if err != nil { |
| 263 | writeJSONError(w, http.StatusInternalServerError, err.Error(), nil) |
| 264 | return |
| 265 | } |
| 266 | |
| 267 | writeJSON(w, http.StatusOK, StopResponse{ |
| 268 | Status: status, |
| 269 | Path: expandedPath, |
| 270 | TXID: txID, |
| 271 | }) |
| 272 | } |
| 273 | |
| 274 | func (s *Server) storeTXID(path string) (uint64, error) { |
| 275 | db := s.store.FindDB(path) |
nothing calls this directly
no test coverage detected