Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reflection: add with_service_name method #1042

Merged
merged 2 commits into from Jul 29, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion tonic-reflection/src/server.rs
Expand Up @@ -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>>,
}

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

service_names: Vec::new(),
use_all_service_names: true,
symbols: HashMap::new(),
}
}
Expand Down Expand Up @@ -94,6 +96,15 @@ impl<'b> Builder<'b> {
self
}

/// Advertise a fully-qualified gRPC service name.
LucioFranco marked this conversation as resolved.
Show resolved Hide resolved
/// 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 {
Expand Down Expand Up @@ -156,7 +167,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 {
Expand Down