MCPcopy
hub / github.com/benbjohnson/litestream / handleUnregister

Method handleUnregister

server.go:630–680  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

628}
629
630func (s *Server) handleUnregister(w http.ResponseWriter, r *http.Request) {
631 var req UnregisterDatabaseRequest
632 if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
633 writeJSONError(w, http.StatusBadRequest, "invalid request body", err.Error())
634 return
635 }
636
637 if req.Path == "" {
638 writeJSONError(w, http.StatusBadRequest, "path required", nil)
639 return
640 }
641
642 expandedPath, err := s.expandPath(req.Path)
643 if err != nil {
644 writeJSONError(w, http.StatusBadRequest, fmt.Sprintf("invalid path: %v", err), nil)
645 return
646 }
647
648 // Set up timeout context. Treat non-positive values as default.
649 timeout := req.Timeout
650 if timeout <= 0 {
651 timeout = 30
652 }
653 ctx, cancel := context.WithTimeout(s.ctx, time.Duration(timeout)*time.Second)
654 defer cancel()
655
656 db := s.store.FindDB(expandedPath)
657
658 // Remove database from store (this also closes it).
659 if err := s.store.UnregisterDB(ctx, expandedPath); err != nil {
660 writeJSONError(w, http.StatusInternalServerError, fmt.Sprintf("failed to unregister database: %v", err), nil)
661 return
662 }
663 var txID uint64
664 status := "already_unregistered"
665 if db != nil {
666 _, maxTXID, err := db.MaxLTX()
667 if err != nil {
668 writeJSONError(w, http.StatusInternalServerError, fmt.Sprintf("failed to read final txid: %v", err), nil)
669 return
670 }
671 txID = uint64(maxTXID)
672 status = "unregistered"
673 }
674
675 writeJSON(w, http.StatusOK, UnregisterDatabaseResponse{
676 Status: status,
677 Path: expandedPath,
678 TXID: txID,
679 })
680}

Callers

nothing calls this directly

Calls 7

expandPathMethod · 0.95
writeJSONErrorFunction · 0.85
writeJSONFunction · 0.85
FindDBMethod · 0.80
UnregisterDBMethod · 0.80
MaxLTXMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected