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

Method handleSyncStatus

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

Source from the content-addressed store, hash-verified

315}
316
317func (s *Server) handleSyncStatus(w http.ResponseWriter, r *http.Request) {
318 path := r.URL.Query().Get("path")
319 if path != "" {
320 expandedPath, err := s.expandPath(path)
321 if err != nil {
322 writeJSONError(w, http.StatusBadRequest, fmt.Sprintf("invalid path: %v", err), nil)
323 return
324 }
325
326 db := s.store.FindDB(expandedPath)
327 if db == nil {
328 writeJSONError(w, http.StatusNotFound, "database not found", nil)
329 return
330 }
331
332 writeJSON(w, http.StatusOK, SyncDiagnosticsResponse{
333 Databases: []SyncDiagnostic{db.SyncDiagnostic()},
334 })
335 return
336 }
337
338 dbs := s.store.DBs()
339 diagnostics := make([]SyncDiagnostic, 0, len(dbs))
340 for _, db := range dbs {
341 diagnostics = append(diagnostics, db.SyncDiagnostic())
342 }
343 writeJSON(w, http.StatusOK, SyncDiagnosticsResponse{Databases: diagnostics})
344}
345
346func writeJSON(w http.ResponseWriter, status int, v interface{}) {
347 w.Header().Set("Content-Type", "application/json")

Callers

nothing calls this directly

Calls 6

expandPathMethod · 0.95
writeJSONErrorFunction · 0.85
writeJSONFunction · 0.85
FindDBMethod · 0.80
SyncDiagnosticMethod · 0.80
DBsMethod · 0.80

Tested by

no test coverage detected