feat: Rename api related to protobuf (#1224)

This commit is contained in:
tottoto
2023-01-10 11:16:57 -05:00
committed by GitHub
parent 0d35d7fbaf
commit d2542dc034
5 changed files with 25 additions and 24 deletions
+9 -9
View File
@@ -24,22 +24,22 @@
use std::fmt::{Display, Formatter};
/// Generated protobuf types from the `grpc.health.v1` package.
pub mod proto {
pub mod pb {
#![allow(unreachable_pub)]
#![allow(missing_docs)]
include!("generated/grpc.health.v1.rs");
pub const GRPC_HEALTH_V1_FILE_DESCRIPTOR_SET: &[u8] =
include_bytes!("generated/grpc_health_v1.bin");
/// Byte encoded FILE_DESCRIPTOR_SET.
pub const FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("generated/grpc_health_v1.bin");
#[cfg(test)]
mod tests {
use super::GRPC_HEALTH_V1_FILE_DESCRIPTOR_SET;
use super::FILE_DESCRIPTOR_SET;
use prost::Message as _;
#[test]
fn file_descriptor_set_is_valid() {
prost_types::FileDescriptorSet::decode(GRPC_HEALTH_V1_FILE_DESCRIPTOR_SET).unwrap();
prost_types::FileDescriptorSet::decode(FILE_DESCRIPTOR_SET).unwrap();
}
}
}
@@ -67,12 +67,12 @@ impl Display for ServingStatus {
}
}
impl From<ServingStatus> for proto::health_check_response::ServingStatus {
impl From<ServingStatus> for pb::health_check_response::ServingStatus {
fn from(s: ServingStatus) -> Self {
match s {
ServingStatus::Unknown => proto::health_check_response::ServingStatus::Unknown,
ServingStatus::Serving => proto::health_check_response::ServingStatus::Serving,
ServingStatus::NotServing => proto::health_check_response::ServingStatus::NotServing,
ServingStatus::Unknown => pb::health_check_response::ServingStatus::Unknown,
ServingStatus::Serving => pb::health_check_response::ServingStatus::Serving,
ServingStatus::NotServing => pb::health_check_response::ServingStatus::NotServing,
}
}
}
+8 -8
View File
@@ -1,7 +1,7 @@
//! Contains all healthcheck based server utilities.
use crate::proto::health_server::{Health, HealthServer};
use crate::proto::{HealthCheckRequest, HealthCheckResponse};
use crate::pb::health_server::{Health, HealthServer};
use crate::pb::{HealthCheckRequest, HealthCheckResponse};
use crate::ServingStatus;
use std::collections::HashMap;
use std::pin::Pin;
@@ -132,7 +132,7 @@ impl Health for HealthService {
match status {
None => Err(Status::not_found("service not registered")),
Some(status) => Ok(Response::new(HealthCheckResponse {
status: crate::proto::health_check_response::ServingStatus::from(status) as i32,
status: crate::pb::health_check_response::ServingStatus::from(status) as i32,
})),
}
}
@@ -152,11 +152,11 @@ impl Health for HealthService {
let output = async_stream::try_stream! {
// yield the current value
let status = crate::proto::health_check_response::ServingStatus::from(*status_rx.borrow()) as i32;
let status = crate::pb::health_check_response::ServingStatus::from(*status_rx.borrow()) as i32;
yield HealthCheckResponse { status };
while let Ok(_) = status_rx.changed().await {
let status = crate::proto::health_check_response::ServingStatus::from(*status_rx.borrow()) as i32;
let status = crate::pb::health_check_response::ServingStatus::from(*status_rx.borrow()) as i32;
yield HealthCheckResponse { status };
}
};
@@ -167,8 +167,8 @@ impl Health for HealthService {
#[cfg(test)]
mod tests {
use crate::proto::health_server::Health;
use crate::proto::HealthCheckRequest;
use crate::pb::health_server::Health;
use crate::pb::HealthCheckRequest;
use crate::server::{HealthReporter, HealthService};
use crate::ServingStatus;
use tokio::sync::watch;
@@ -176,7 +176,7 @@ mod tests {
use tonic::{Code, Request, Status};
fn assert_serving_status(wire: i32, expected: ServingStatus) {
let expected = crate::proto::health_check_response::ServingStatus::from(expected) as i32;
let expected = crate::pb::health_check_response::ServingStatus::from(expected) as i32;
assert_eq!(wire, expected);
}