Skip to main content

nym_node_requests/api/v1/health/
models.rs

1// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
2// SPDX-License-Identifier: Apache-2.0
3
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6use std::time::Duration;
7
8#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
9#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
10pub struct NodeHealth {
11    pub status: NodeStatus,
12    pub uptime: u64,
13}
14
15impl NodeHealth {
16    pub fn new_healthy(uptime: Duration) -> Self {
17        NodeHealth {
18            status: NodeStatus::Up,
19            uptime: uptime.as_secs(),
20        }
21    }
22}
23
24#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
25#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
26#[serde(rename_all = "camelCase")]
27pub enum NodeStatus {
28    Up,
29}
30
31impl NodeStatus {
32    pub fn is_up(&self) -> bool {
33        matches!(self, NodeStatus::Up)
34    }
35}