Skip to content

Commit 4288fd3

Browse files
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 <luciofranco14@gmail.com>
1 parent e40ae11 commit 4288fd3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tonic-reflection/src/server.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub struct Builder<'b> {
5353
include_reflection_service: bool,
5454

5555
service_names: Vec<String>,
56+
use_all_service_names: bool,
5657
symbols: HashMap<String, Arc<FileDescriptorProto>>,
5758
}
5859

@@ -65,6 +66,7 @@ impl<'b> Builder<'b> {
6566
include_reflection_service: true,
6667

6768
service_names: Vec::new(),
69+
use_all_service_names: true,
6870
symbols: HashMap::new(),
6971
}
7072
}
@@ -94,6 +96,16 @@ impl<'b> Builder<'b> {
9496
self
9597
}
9698

99+
/// Advertise a fully-qualified gRPC service name.
100+
///
101+
/// If not called, then all services present in the registered file descriptor sets
102+
/// will be advertised.
103+
pub fn with_service_name(mut self, name: impl Into<String>) -> Self {
104+
self.use_all_service_names = false;
105+
self.service_names.push(name.into());
106+
self
107+
}
108+
97109
/// Build a gRPC Reflection Service to be served via Tonic.
98110
pub fn build(mut self) -> Result<ServerReflectionServer<impl ServerReflection>, Error> {
99111
if self.include_reflection_service {
@@ -156,7 +168,9 @@ impl<'b> Builder<'b> {
156168

157169
for service in &fd.service {
158170
let service_name = extract_name(prefix, "service", service.name.as_ref())?;
159-
self.service_names.push(service_name.clone());
171+
if self.use_all_service_names {
172+
self.service_names.push(service_name.clone());
173+
}
160174
self.symbols.insert(service_name.clone(), fd.clone());
161175

162176
for method in &service.method {

0 commit comments

Comments
 (0)