Skip to content

Commit

Permalink
add /api/tables endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyuyureka committed Jan 22, 2025
1 parent 33be446 commit 5314a24
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ async fn query<T: Store>(
Ok(Body::from_stream(stream))
}

async fn tables<T: Store>(State(AppState { store, .. }): State<AppState<T>>) -> impl IntoResponse {
serde_json::to_string(&store.get_tables()).unwrap()
}
async fn routers<T: Store>(State(AppState { store, .. }): State<AppState<T>>) -> impl IntoResponse {
serde_json::to_string(&store.get_routers()).unwrap()
}
Expand Down Expand Up @@ -371,6 +374,7 @@ async fn make_api<T: Store>(cfg: ApiServerConfig, store: T) -> anyhow::Result<Ro
Ok(Router::new()
.route("/query", get(query::<T>))
.route("/routers", get(routers::<T>))
.route("/tables", get(tables::<T>))
.route("/routing-instances", get(routing_instances::<T>))
.with_state(AppState {
cfg: Arc::new(cfg),
Expand Down
2 changes: 2 additions & 0 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ pub trait Store: Clone + Send + Sync + 'static {

fn get_routes(&self, query: Query) -> Pin<Box<dyn Stream<Item = QueryResult> + Send>>;

fn get_tables(&self) -> Vec<TableSelector>;

fn get_routers(&self) -> HashMap<SocketAddr, Client>;

fn get_routing_instances(&self) -> HashMap<SocketAddr, HashSet<RouteDistinguisher>>;
Expand Down
4 changes: 4 additions & 0 deletions src/store_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ impl Store for InMemoryStore {
)
}

fn get_tables(&self) -> Vec<TableSelector> {
self.tables.lock().unwrap().keys().cloned().collect()
}

fn get_routers(&self) -> HashMap<SocketAddr, Client> {
self.clients.lock().unwrap().clone()
}
Expand Down

0 comments on commit 5314a24

Please sign in to comment.