A gRPC client library for Firestore, intended to run on Cloud Run.
Add this to your Cargo.toml
:
toml
[dependencies]
firestore = { version = "0.1", package = "firestore_grpc_cloudrun" }
CreateDocument
src/main.rs
``` rust use firestore::*; use futures::tryjoin; use hyper::service::{makeservicefn, servicefn}; use hyper::{Body, Request, Response, Server}; use std::convert::Infallible; use std::net::SocketAddr;
async fn main() { let addr = SocketAddr::from(([0, 0, 0, 0], get_port()));
let make_svc = make_service_fn(|_conn| async {
Ok::<_, Infallible>(service_fn(root))
});
let server = Server::bind(&addr).serve(make_svc);
if let Err(e) = server.await {
eprintln!("server error: {}", e);
}
}
async fn root(req: Request) -> Result
async fn createdocument() -> Result
fn getport() -> u16 { std::env::var("PORT") .ok() .andthen(|x| x.parse().ok()) .unwrap_or(8080) } ```
Cargo.toml
toml
[dependencies]
firestore = { version = "*", package = "firestore_grpc_cloudrun" }
futures = "0.3"
hyper = "0.13"
tokio = { version = "0.2", features = ["full"] }
Dockerfile
``` Dockerfile FROM rust:1-stretch as build-env WORKDIR /app ADD . . RUN rustup update && rustup component add rustfmt && cargo build --release
FROM debian:stretch-slim WORKDIR /app RUN apt-get update && apt-get install -y libgcc1 libgomp1 libstdc++6 ca-certificates && update-ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=build-env /app/target/release/cloudfunction-firestore /app/main ENTRYPOINT ["./main"]
```