You've already forked AstralRinth
forked from didirus/AstralRinth
* refactor: improve error handling * fix: specify bind address instead of port * fix: remove temporary testing file * fix(errors): change error names to snake_case * refactor(errors): split indexing error types, remove unused errors * feat: add env variable checking at program start This just checks whether the enviroment variables exist and can parse to the given type and gives a warning if they can't. This should prevent cases where the program fails at runtime due to checking an environment variable that doesn't exist.
15 lines
463 B
Rust
15 lines
463 B
Rust
use log::info;
|
|
use mongodb::error::Error;
|
|
use mongodb::options::ClientOptions;
|
|
use mongodb::Client;
|
|
|
|
pub async fn connect() -> Result<Client, Error> {
|
|
info!("Initializing database connection");
|
|
|
|
let mongodb_addr = dotenv::var("MONGODB_ADDR").expect("`MONGO_ADDR` not in .env");
|
|
let mut client_options = ClientOptions::parse(&mongodb_addr).await?;
|
|
client_options.app_name = Some("labrinth".to_string());
|
|
|
|
Client::with_options(client_options)
|
|
}
|