Files
go-service/cmd/server/web/js/data.ts

31 lines
694 B
TypeScript

// data.js (API слой)
// Типы ответов от сервера
interface HealthResponse {
status: string;
uptime_sec: number;
last_data_ms: number;
pipe_alive: boolean;
has_data: boolean;
latest: number;
stats: {
filled: number;
bytes_per_sec: number;
};
}
interface HistoryResponse {
bytes: number[];
}
export async function fetchHealth(): Promise<HealthResponse> {
const r = await fetch("/api/health");
if (!r.ok) throw new Error(`HTTP ${r.status}`);
return r.json();
}
export async function fetchHistory(): Promise<HistoryResponse> {
const r = await fetch("/api/history");
if (!r.ok) throw new Error(`HTTP ${r.status}`);
return r.json();
}