Skip to content

Commit

Permalink
version endpoint & details
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmanczak committed Jul 13, 2024
1 parent 1fa860b commit 1a43258
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
11 changes: 11 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use std::process::Command;

fn main() {
match Command::new("git").args(&["rev-parse", "HEAD"]).output() {
Ok(output) => match String::from_utf8(output.stdout) {
Ok(hash) => println!("cargo:rustc-env=GIT_HASH={}", hash),
Err(_) => (),
},
Err(_) => (),
};
}
8 changes: 5 additions & 3 deletions src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use axum::Router;

pub mod health;
pub mod splash;
pub mod teapot;
mod health;
mod splash;
mod teapot;
mod version;

pub fn routes() -> Router {
Router::new()
.merge(health::route())
.merge(splash::route())
.merge(teapot::route())
.merge(version::route())
}
44 changes: 44 additions & 0 deletions src/routes/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use axum::{
response::{IntoResponse, Response},
routing::get,
Json, Router,
};
use serde::Serialize;

pub fn route() -> Router {
Router::new()
.route("/version", get(version))
.route("/version-details", get(version_details))
.route("/info", get(version_details))
}

#[derive(Serialize)]
struct VersionDetails {
version: &'static str,
version_bits: VersionBits,
git_commit_hash: &'static str,
}

#[derive(Serialize)]
struct VersionBits {
major: &'static str,
minor: &'static str,
patch: &'static str,
}

async fn version() -> Response {
env!("CARGO_PKG_VERSION").into_response()
}

async fn version_details() -> Response {
Json(VersionDetails {
version: env!("CARGO_PKG_VERSION"),
version_bits: VersionBits {
major: env!("CARGO_PKG_VERSION_MAJOR"),
minor: env!("CARGO_PKG_VERSION_MINOR"),
patch: env!("CARGO_PKG_VERSION_PATCH"),
},
git_commit_hash: env!("GIT_HASH"),
})
.into_response()
}

0 comments on commit 1a43258

Please sign in to comment.