reflection: add with_service_name method (#1042)

* reflection: add with_service_name method

Fixes: #682

* Update tonic-reflection/src/server.rs

Co-authored-by: Lucio Franco <[email protected]>
This commit is contained in:
Ross Light
2022-07-29 14:30:33 -04:00
committed by GitHub
co-authored by Lucio Franco
parent e40ae113ad
commit 4288fd3517
+15 -1
View File
@@ -53,6 +53,7 @@ pub struct Builder<'b> {
include_reflection_service: bool,
service_names: Vec<String>,
use_all_service_names: bool,
symbols: HashMap<String, Arc<FileDescriptorProto>>,
}
@@ -65,6 +66,7 @@ impl<'b> Builder<'b> {
include_reflection_service: true,
service_names: Vec::new(),
use_all_service_names: true,
symbols: HashMap::new(),
}
}
@@ -94,6 +96,16 @@ impl<'b> Builder<'b> {
self
}
/// Advertise a fully-qualified gRPC service name.
///
/// If not called, then all services present in the registered file descriptor sets
/// will be advertised.
pub fn with_service_name(mut self, name: impl Into<String>) -> Self {
self.use_all_service_names = false;
self.service_names.push(name.into());
self
}
/// Build a gRPC Reflection Service to be served via Tonic.
pub fn build(mut self) -> Result<ServerReflectionServer<impl ServerReflection>, Error> {
if self.include_reflection_service {
@@ -156,7 +168,9 @@ impl<'b> Builder<'b> {
for service in &fd.service {
let service_name = extract_name(prefix, "service", service.name.as_ref())?;
self.service_names.push(service_name.clone());
if self.use_all_service_names {
self.service_names.push(service_name.clone());
}
self.symbols.insert(service_name.clone(), fd.clone());
for method in &service.method {