feat: add protos
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-05-11 16:23:52 +02:00
parent 113c646334
commit 86cba91b16
10 changed files with 454 additions and 28 deletions

View File

@@ -4,12 +4,55 @@ use crate::state::{SharedState, State};
mod external_http;
mod internal_http;
mod external_grpc {
use std::net::SocketAddr;
use hyperlog_protos::hyperlog::{
graph_server::{Graph, GraphServer},
HelloReply, HelloRequest,
};
use tonic::{transport, Response};
use crate::state::SharedState;
#[derive(Default)]
struct Server {}
#[tonic::async_trait]
impl Graph for Server {
async fn say_hello(
&self,
request: tonic::Request<HelloRequest>,
) -> std::result::Result<tonic::Response<HelloReply>, tonic::Status> {
tracing::info!("received hello request");
Ok(Response::new(HelloReply {
message: "hello".into(),
}))
}
}
pub async fn serve(state: &SharedState, host: SocketAddr) -> anyhow::Result<()> {
tracing::info!("listening on {}", host);
let graph_server = Server::default();
transport::Server::builder()
.add_service(GraphServer::new(graph_server))
.serve(host)
.await?;
Ok(())
}
}
mod state;
#[derive(Clone)]
pub struct ServeOptions {
pub external_http: SocketAddr,
pub internal_http: SocketAddr,
pub external_grpc: SocketAddr,
}
pub async fn serve(opts: ServeOptions) -> anyhow::Result<()> {
@@ -28,6 +71,9 @@ pub async fn serve(opts: ServeOptions) -> anyhow::Result<()> {
res = internal_http::serve(&state, &opts.internal_http) => {
res?
},
res = external_grpc::serve(&state, opts.external_grpc) => {
res?
}
() = ctrl_c => {}
);
tracing::debug!("serve finalized");