Skip to content

Commit 0666b7d

Browse files
committed
Add /version route
Signed-off-by: Lilly Rose Berner <[email protected]>
1 parent 510e72f commit 0666b7d

File tree

6 files changed

+27
-3
lines changed

6 files changed

+27
-3
lines changed

echo/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

echo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "echo"
3-
version = "1.0.0"
3+
version = "5.0.0-alpha.1"
44
publish = false
55
edition = "2021"
66

echo/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fn rocket() -> _ {
2626
meta::get_docs,
2727
meta::get_spec,
2828
meta::get_health,
29+
meta::get_version,
2930
pastes::get_paste,
3031
pastes::create_paste_simple,
3132
pastes::create_paste_structured,

echo/src/models/meta.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use serde::Serialize;
2+
3+
#[derive(Clone, Copy, Serialize)]
4+
pub struct Version {
5+
version: &'static str,
6+
}
7+
8+
impl Version {
9+
const fn new() -> Self {
10+
Version {
11+
version: env!("CARGO_PKG_VERSION"),
12+
}
13+
}
14+
}
15+
16+
pub static VERSION: Version = Version::new();

echo/src/models/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
pub mod meta;
12
pub mod pastes;
23
pub mod security;

echo/src/routes/meta.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use scalar_doc::{Documentation, Theme};
1515

1616
use crate::{
1717
database::PgDatabase,
18+
models::meta::{Version, VERSION},
1819
result::{HTTPError, Result},
1920
};
2021

@@ -47,3 +48,8 @@ pub async fn get_health(mut db: Connection<PgDatabase>) -> Result<String> {
4748
Err(_) => Err(HTTPError::new(503, "Database connection unhealthy.")),
4849
}
4950
}
51+
52+
#[get("/version")]
53+
pub async fn get_version() -> Json<Version> {
54+
Json(VERSION)
55+
}

0 commit comments

Comments
 (0)