brane_reg/
version.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//  VERSION.rs
//    by Lut99
//
//  Created:
//    26 Sep 2022, 15:39:41
//  Last edited:
//    26 Sep 2022, 15:58:37
//  Auto updated?
//    Yes
//
//  Description:
//!   Implements the function(s) that handle the `/version` path(s).
//

use log::debug;
use warp::http::HeaderValue;
use warp::hyper::Body;
use warp::reply::Response;
use warp::{Rejection, Reply};


/***** LIBRARY *****/
/// Handles a GET on the main `/version` path, returning the version number of this service.
///
/// # Returns
/// The response that can be send back to the client. Simply contains the string 'vXX.YY.ZZ', where
/// - `XX` is the major version;
/// - `YY` is the minor version; and
/// - `ZZ` is the patch version.
///
/// # Errors
/// This function doesn't usually error.
pub async fn get() -> Result<impl Reply, Rejection> {
    debug!("Handling GET on `/version` (i.e., get service version)...");

    // Parse Cargo's version number
    let version = env!("CARGO_PKG_VERSION");
    let version = format!("v{version}");
    let version_len = version.len();

    // Construct a response with the body and the content-length header
    let mut response = Response::new(Body::from(version));
    response.headers_mut().insert("Content-Length", HeaderValue::from(version_len));

    // Done
    Ok(response)
}