Implement whoami

This commit is contained in:
Daan Wynen 2022-09-24 12:13:08 +02:00
parent f5fcba65eb
commit 548cf22d43
3 changed files with 700 additions and 21 deletions

695
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,3 +7,4 @@ edition = "2021"
[dependencies]
rocket = "0.5.0-rc.1"
golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi.git" }

View File

@ -1,8 +1,31 @@
use std::env;
use rocket::{get, launch, routes};
use golgi::{sbot::Keystore, Sbot};
async fn init_sbot() -> Result<Sbot, String> {
let go_sbot_port = env::var("GO_SBOT_PORT").unwrap_or_else(|_| "8021".to_string());
let keystore = Keystore::GoSbot;
let ip_port = Some(format!("127.0.0.1:{}", go_sbot_port));
let net_id = None;
Sbot::init(keystore, ip_port, net_id)
.await
.map_err(|e| e.to_string())
}
async fn whoami() -> Result<String, String> {
let mut sbort = init_sbot().await?;
sbort.whoami().await.map_err(|e| e.to_string())
}
#[get("/")]
async fn home() -> String {
String::from("lykin")
match whoami().await {
Ok(id) => id,
Err(e) => format!("whoami call failed: {}", e),
}
}
#[launch]