-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fa860b
commit 1a43258
Showing
3 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(_) => (), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |