Skip to content

Commit

Permalink
utilize a type alias to get the get_version signature shorter
Browse files Browse the repository at this point in the history
Signed-off-by: clux <[email protected]>
  • Loading branch information
clux committed Dec 21, 2023
1 parent 1e834a4 commit 8b41d7f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct Entry {
namespace: String,
version: String,
}
type Cache = reflector::Store<Deployment>;

fn deployment_to_entry(d: &Deployment) -> Option<Entry> {
let name = d.name_any();
Expand All @@ -32,7 +33,7 @@ fn deployment_to_entry(d: &Deployment) -> Option<Entry> {
}

#[instrument(skip(store))]
async fn get_versions(State(store): State<reflector::Store<Deployment>>) -> Json<Vec<Entry>> {
async fn get_versions(State(store): State<Cache>) -> Json<Vec<Entry>> {
let data = store.state().iter().filter_map(|d| deployment_to_entry(d)).collect();
Json(data)
}
Expand All @@ -45,10 +46,7 @@ struct EntryPath {
}

#[instrument(skip(store))]
async fn get_version(
State(store): State<reflector::Store<Deployment>>,
path: EntryPath,
) -> impl IntoResponse {
async fn get_version(State(store): State<Cache>, path: EntryPath) -> impl IntoResponse {
let key = reflector::ObjectRef::new(&path.name).within(&path.namespace);
if let Some(Some(e)) = store.get(&key).map(|d| deployment_to_entry(&d)) {
return Ok(Json(e));
Expand Down

0 comments on commit 8b41d7f

Please sign in to comment.