Extract dotenv initialization from init_pool because it affects not only database
This commit is contained in:
		
							parent
							
								
									7f1b33a567
								
							
						
					
					
						commit
						29f2239e3f
					
				
							
								
								
									
										12
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/main.rs
									
									
									
									
									
								
							@ -50,12 +50,6 @@ compile_i18n!();
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/// Initializes a database pool.
 | 
					/// Initializes a database pool.
 | 
				
			||||||
fn init_pool() -> Option<DbPool> {
 | 
					fn init_pool() -> Option<DbPool> {
 | 
				
			||||||
    match dotenv::dotenv() {
 | 
					 | 
				
			||||||
        Ok(path) => println!("Configuration read from {}", path.display()),
 | 
					 | 
				
			||||||
        Err(ref e) if e.not_found() => eprintln!("no .env was found"),
 | 
					 | 
				
			||||||
        e => e.map(|_| ()).unwrap(),
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let manager = ConnectionManager::<Connection>::new(CONFIG.database_url.as_str());
 | 
					    let manager = ConnectionManager::<Connection>::new(CONFIG.database_url.as_str());
 | 
				
			||||||
    let mut builder = DbPool::builder()
 | 
					    let mut builder = DbPool::builder()
 | 
				
			||||||
        .connection_customizer(Box::new(PragmaForeignKey))
 | 
					        .connection_customizer(Box::new(PragmaForeignKey))
 | 
				
			||||||
@ -69,6 +63,12 @@ fn init_pool() -> Option<DbPool> {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn main() {
 | 
					fn main() {
 | 
				
			||||||
 | 
					    match dotenv::dotenv() {
 | 
				
			||||||
 | 
					        Ok(path) => println!("Configuration read from {}", path.display()),
 | 
				
			||||||
 | 
					        Err(ref e) if e.not_found() => eprintln!("no .env was found"),
 | 
				
			||||||
 | 
					        e => e.map(|_| ()).unwrap(),
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    App::new("Plume")
 | 
					    App::new("Plume")
 | 
				
			||||||
        .bin_name("plume")
 | 
					        .bin_name("plume")
 | 
				
			||||||
        .version(env!("CARGO_PKG_VERSION"))
 | 
					        .version(env!("CARGO_PKG_VERSION"))
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user