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

@@ -0,0 +1,12 @@
[package]
name = "hyperlog-protos"
edition = "2021"
version.workspace = true
[dependencies]
tonic.workspace = true
prost = "0.12.4"
[build-dependencies]
tonic-build = "0.11.0"

View File

@@ -0,0 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/hyperlog.proto").unwrap();
}

View File

@@ -0,0 +1,16 @@
syntax = "proto3";
package hyperlog;
service Graph {
rpc SayHello (HelloRequest) returns (HelloReply);
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}

View File

@@ -0,0 +1,3 @@
pub mod hyperlog {
tonic::include_proto!("hyperlog"); // Specify the same package name as in your .proto file
}

View File

@@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
hyperlog-core.workspace = true
hyperlog-protos.workspace = true
anyhow.workspace = true
tokio.workspace = true
@@ -13,6 +14,7 @@ axum.workspace = true
serde.workspace = true
serde_json.workspace = true
uuid.workspace = true
tonic.workspace = true
tower-http = { version = "0.5.2", features = ["cors", "trace"] }
sqlx = { version = "0.7.4", features = [

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");

View File

@@ -78,13 +78,14 @@ pub async fn execute() -> anyhow::Result<()> {
Some(Commands::Serve {
external_host,
internal_host,
..
external_grpc_host,
}) => {
tracing::info!("Starting service");
hyperlog_server::serve(hyperlog_server::ServeOptions {
external_http: external_host,
internal_http: internal_host,
external_grpc: external_grpc_host,
})
.await?;
}