generated from Patagia/template-nix
43 lines
1.1 KiB
Rust
43 lines
1.1 KiB
Rust
use dropshot::{endpoint, HttpError, HttpResponseOk, RequestContext};
|
|
use schemars::JsonSchema;
|
|
use serde::Serialize;
|
|
use trace_request::trace_request;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use crate::context::ControllerContext;
|
|
|
|
/// Version and build information
|
|
#[derive(Serialize, JsonSchema)]
|
|
struct VersionInfo {
|
|
name: String,
|
|
version: String,
|
|
}
|
|
|
|
/// Fetch version info.
|
|
#[endpoint {
|
|
method = GET,
|
|
path = "/version",
|
|
}]
|
|
#[trace_request]
|
|
pub(crate) async fn version(
|
|
rqctx: RequestContext<Arc<ControllerContext>>,
|
|
) -> Result<HttpResponseOk<VersionInfo>, HttpError> {
|
|
let ver = VersionInfo {
|
|
name: env!("CARGO_PKG_NAME").to_string(),
|
|
version: env!("CARGO_PKG_VERSION").to_string(),
|
|
};
|
|
|
|
tracing::info_span!("Hello, span!");
|
|
|
|
tracing::info!(monotonic_counter.version_calls = 1);
|
|
|
|
async move {
|
|
tracing::info!("Someone made a request to /version");
|
|
tokio::time::sleep(std::time::Duration::from_millis(200)).await;
|
|
}
|
|
.instrument(tracing::info_span!("Let's do the thing...."))
|
|
.await;
|
|
|
|
Ok(HttpResponseOk(ver))
|
|
}
|