split into modules
This commit is contained in:
parent
548cf22d43
commit
d8cd8804e6
31
src/main.rs
31
src/main.rs
|
@ -1,32 +1,9 @@
|
||||||
use std::env;
|
mod routes;
|
||||||
|
mod sbot;
|
||||||
|
|
||||||
use rocket::{get, launch, routes};
|
use rocket::{launch, routes};
|
||||||
use golgi::{sbot::Keystore, Sbot};
|
|
||||||
|
|
||||||
async fn init_sbot() -> Result<Sbot, String> {
|
use crate::routes::*;
|
||||||
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 {
|
|
||||||
match whoami().await {
|
|
||||||
Ok(id) => id,
|
|
||||||
Err(e) => format!("whoami call failed: {}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[launch]
|
#[launch]
|
||||||
async fn rocket() -> _ {
|
async fn rocket() -> _ {
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
use rocket::get;
|
||||||
|
|
||||||
|
use crate::sbot;
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
pub async fn home() -> String {
|
||||||
|
match sbot::whoami().await {
|
||||||
|
Ok(id) => id,
|
||||||
|
Err(e) => format!("whoami call failed: {}", e),
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
use golgi::{sbot::Keystore, Sbot};
|
||||||
|
|
||||||
|
|
||||||
|
pub 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())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn whoami() -> Result<String, String> {
|
||||||
|
let mut sbort = init_sbot().await?;
|
||||||
|
sbort.whoami().await.map_err(|e| e.to_string())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue