-
I would like to be able to import a protofile into another. Compiling and accessing the members of each protocol separately works fine, but they cannot access each other in the generated code as this error message shows:
My project
// ../protos/events_service/user.proto
syntax = "proto3";
import "google/protobuf/empty.proto";
import "shared.proto";
package user;
option go_package = "github.com/dk-slack/protos/events_service/golang/user";
service Events {
rpc List ( google.protobuf.Empty ) returns ( shared.EventList );
} // ../protos/events_service/shared.proto
syntax = "proto3";
package shared;
option go_package = "github.com/dk-slack/protos/events_service/golang/shared";
message EventList {
repeated shared.Event events = 1;
}
message Event {
enum EventType {
WEEKLYMEETING = 0;
WATERLINE = 1;
HIGHLINE = 2;
MEETING = 3;
WORKSHOP = 4;
AUDIT = 5;
RIGGING = 6;
}
message Location {
message Coordinates {
float lng = 1;
float lat = 2;
}
string name = 1;
Coordinates coordinates = 2;
}
string title = 1;
Location location = 2;
EventType event_type = 3;
uint64 time = 4;
} // build.rs
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::configure().build_server(false).compile(
&[
"../protos/events_service/user.proto",
"../protos/events_service/shared.proto",
],
&["../protos/events_service"],
)?;
Ok(())
} // src/lib.rs
mod events {
tonic::include_proto!("user");
}
mod proto_shared {
tonic::include_proto!("shared");
}
use proto_shared::event::EventType as ET;
use tonic::transport::Channel;
pub use shared::errors::UserEventError;
#[derive(Clone)]
pub struct UserEventsClient {
cli: events::events_client::EventsClient<Channel>,
}
impl UserEventsClient {
pub async fn new() -> Result<Self, UserEventError> {
Ok(Self {
cli: events::events_client::EventsClient::connect("http://localhost:50057")
.await
.map_err(|_| UserEventError::ConnectionError)?,
})
}
} I had similar issues in golang when importing a package because I was using relative package names imports and go doesn't allow that in modules. So I was forced to specify a fully qualified package name in the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Never mind I just realized that I have to give the module the same name as the package name in the protofile. I was calling it proto_shared instead of shared. |
Beta Was this translation helpful? Give feedback.
Never mind I just realized that I have to give the module the same name as the package name in the protofile.
I was calling it proto_shared instead of shared.