lykin_playalong/src/main.rs

35 lines
820 B
Rust
Raw Normal View History

2022-09-24 10:13:08 +00:00
use std::env;
2022-09-24 09:53:36 +00:00
use rocket::{get, launch, routes};
2022-09-24 10:13:08 +00:00
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())
}
2022-09-24 09:53:36 +00:00
#[get("/")]
async fn home() -> String {
2022-09-24 10:13:08 +00:00
match whoami().await {
Ok(id) => id,
Err(e) => format!("whoami call failed: {}", e),
}
2022-09-24 09:53:36 +00:00
}
#[launch]
async fn rocket() -> _ {
rocket::build().mount("/", routes![home])
2022-09-24 09:42:02 +00:00
}