lib.rs for functions outside main

This commit is contained in:
LinlyBoi
2023-12-17 23:33:40 +02:00
parent b5536659a6
commit caec9f6092
2 changed files with 23 additions and 0 deletions

22
src/lib.rs Normal file
View File

@@ -0,0 +1,22 @@
use std::env;
pub fn init_address() -> (String, u16) {
let port: u16 = env::var("ACTIX_PORT")
.expect("SET ACTIX_PORT PLOX")
.parse()
.expect("Couldn't parse the ACTIX_PORT variable >:(");
let address = env::var("ACTIX_IP").expect("SET ACTIX_IP PLEASE");
(address, port)
}
use sqlx::Pool;
pub async fn init_dbpool() -> Pool<sqlx::Postgres> {
use sqlx::postgres::PgPoolOptions;
let database_url = env::var("DATABASE_URL").expect("Put a DB url in the .env file dumbass");
let pool = PgPoolOptions::new()
.max_connections(10)
.connect(database_url.as_str())
.await
.expect("No pool connection man :(");
pool
}