mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 07:24:52 +01:00
build: finished following tonic tutorial
This commit is contained in:
parent
65300edf90
commit
6e26282faf
3 changed files with 45 additions and 8 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1,3 @@
|
|||
/target
|
||||
|
||||
Cargo.lock
|
||||
|
|
|
@ -1,13 +1,21 @@
|
|||
use tonic::{transport::Server, Request, Response, Status};
|
||||
|
||||
pub mod proto_core {
|
||||
tonic::include_proto!("core");
|
||||
}
|
||||
|
||||
use proto_core::session_server::{Session, SessionServer};
|
||||
use proto_core::{SessionRequest, SessionResponse};
|
||||
use proto_core::session_client::SessionClient;
|
||||
use proto_core::SessionRequest;
|
||||
|
||||
pub fn main() {
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut client = SessionClient::connect("http://[::1]:50051").await?;
|
||||
|
||||
let request = tonic::Request::new(SessionRequest {
|
||||
session_id: 0,
|
||||
});
|
||||
|
||||
let response = client.create(request).await?;
|
||||
|
||||
println!("RESPONSE={:?}", response);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,13 +1,40 @@
|
|||
use tonic::{transport::Server, Request, Response, Status};
|
||||
|
||||
use proto_core::session_server::{Session, SessionServer};
|
||||
use proto_core::{SessionRequest, SessionResponse};
|
||||
|
||||
pub mod proto_core {
|
||||
tonic::include_proto!("core");
|
||||
}
|
||||
|
||||
use proto_core::session_server::{Session, SessionServer};
|
||||
use proto_core::{SessionRequest, SessionResponse};
|
||||
#[derive(Debug, Default)]
|
||||
pub struct TestSession {}
|
||||
|
||||
pub fn main() {
|
||||
#[tonic::async_trait]
|
||||
impl Session for TestSession {
|
||||
async fn create(
|
||||
&self,
|
||||
request: Request<SessionRequest>,
|
||||
) -> Result<Response<SessionResponse>, Status> {
|
||||
println!("Got a request: {:?}", request);
|
||||
|
||||
let reply = proto_core::SessionResponse {
|
||||
session_id: request.into_inner().session_id,
|
||||
};
|
||||
|
||||
Ok(Response::new(reply))
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let addr = "[::1]:50051".parse()?;
|
||||
let greeter = TestSession::default();
|
||||
|
||||
Server::builder()
|
||||
.add_service(SessionServer::new(greeter))
|
||||
.serve(addr)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue