initial commit

This commit is contained in:
Maple Nebel 2026-06-16 13:47:49 +02:00
commit e9ec719ae5
8 changed files with 2218 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target
.env

2119
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

15
Cargo.toml Normal file
View file

@ -0,0 +1,15 @@
[package]
name = "nex-account"
version = "0.1.0"
edition = "2024"
[dependencies]
prost = "0.14.3"
tonic-prost = "*"
tonic = "0.14.6"
tokio = { version = "1.52.3", features = ["macros", "rt-multi-thread"] }
sqlx = { version = "0.9.0", features = ["postgres"] }
[build-dependencies]
tonic-prost-build = "0.14.6"

7
build.rs Normal file
View file

@ -0,0 +1,7 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=./grpc.proto");
tonic_prost_build::configure().compile_protos(&["./grpc.proto"], &["./"])?;
Ok(())
}

22
grpc.proto Normal file
View file

@ -0,0 +1,22 @@
syntax = "proto3";
package nex_account;
message ActCreateInfoNoPid {
string principal_name = 1;
string key = 2;
string email = 3;
}
message PID {
int32 pid = 1;
}
message NexKey {
string key = 1;
}
service NexAccountService {
rpc CreateNewSequentialOrUpdateAndGetAccount(ActCreateInfoNoPid) returns (PID);
rpc GetNexKeyByPid(PID) returns (NexKey);
}

1
src/grpc.rs Normal file
View file

@ -0,0 +1 @@
tonic::include_proto!("nex_account");

1
src/lib.rs Normal file
View file

@ -0,0 +1 @@
pub mod grpc;

51
src/main.rs Normal file
View file

@ -0,0 +1,51 @@
use std::{
env,
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
};
use sqlx::PgPool;
use tonic::transport::Server;
use crate::grpc::{
ActCreateInfoNoPid, NexKey, Pid,
nex_account_service_server::{NexAccountService, NexAccountServiceServer},
};
pub mod grpc;
pub struct NexAccountServer {
pool: PgPool,
}
#[tonic::async_trait]
impl NexAccountService for NexAccountServer {
async fn create_new_sequential_or_update_and_get_account(
&self,
request: tonic::Request<ActCreateInfoNoPid>,
) -> std::result::Result<tonic::Response<Pid>, tonic::Status> {
todo!()
}
async fn get_nex_key_by_pid(
&self,
request: tonic::Request<Pid>,
) -> std::result::Result<tonic::Response<NexKey>, tonic::Status> {
todo!()
}
}
#[tokio::main]
async fn main() {
let db_url = env::var("DATABASE_URL").expect("database url not specified");
let pool = PgPool::connect(&db_url)
.await
.expect("unable to connect to database");
Server::builder()
.add_service(NexAccountServiceServer::new(NexAccountServer { pool }))
.serve(SocketAddr::V4(SocketAddrV4::new(
Ipv4Addr::UNSPECIFIED,
10000,
)))
.await
.expect("server failed to start");
}