mirror of
https://github.com/actix/examples
synced 2024-11-27 16:02:57 +01:00
Update dependencies for databases/postgres (#555)
Fix config code to account for breaking changes
This commit is contained in:
parent
a7a7f0858b
commit
271a68c07d
353
Cargo.lock
generated
353
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -5,11 +5,11 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
config = "0.11.0"
|
config = "0.13.1"
|
||||||
deadpool-postgres = { version = "0.10.1", features = ["serde"] }
|
deadpool-postgres = { version = "0.10.2", features = ["serde"] }
|
||||||
derive_more = "0.99.2"
|
derive_more = "0.99.17"
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
serde = { version = "1.0.104", features = ["derive"] }
|
serde = { version = "1.0.137", features = ["derive"] }
|
||||||
tokio-pg-mapper = "0.2.0"
|
tokio-pg-mapper = "0.2.0"
|
||||||
tokio-pg-mapper-derive = "0.2.0"
|
tokio-pg-mapper-derive = "0.2.0"
|
||||||
tokio-postgres = "0.7.5"
|
tokio-postgres = "0.7.6"
|
||||||
|
@ -1,18 +1,10 @@
|
|||||||
mod config {
|
mod config {
|
||||||
pub use ::config::ConfigError;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
#[derive(Deserialize)]
|
#[derive(Debug, Default, Deserialize)]
|
||||||
pub struct Config {
|
pub struct ExampleConfig {
|
||||||
pub server_addr: String,
|
pub server_addr: String,
|
||||||
pub pg: deadpool_postgres::Config,
|
pub pg: deadpool_postgres::Config,
|
||||||
}
|
}
|
||||||
impl Config {
|
|
||||||
pub fn from_env() -> Result<Self, ConfigError> {
|
|
||||||
let mut cfg = ::config::Config::new();
|
|
||||||
cfg.merge(::config::Environment::new())?;
|
|
||||||
cfg.try_into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod models {
|
mod models {
|
||||||
@ -106,6 +98,8 @@ mod handlers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use crate::config::ExampleConfig;
|
||||||
|
use ::config::Config;
|
||||||
use actix_web::{web, App, HttpServer};
|
use actix_web::{web, App, HttpServer};
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use handlers::add_user;
|
use handlers::add_user;
|
||||||
@ -115,7 +109,13 @@ use tokio_postgres::NoTls;
|
|||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
|
|
||||||
let config = crate::config::Config::from_env().unwrap();
|
let config_ = Config::builder()
|
||||||
|
.add_source(::config::Environment::default())
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let config: ExampleConfig = config_.try_deserialize().unwrap();
|
||||||
|
|
||||||
let pool = config.pg.create_pool(None, NoTls).unwrap();
|
let pool = config.pg.create_pool(None, NoTls).unwrap();
|
||||||
|
|
||||||
let server = HttpServer::new(move || {
|
let server = HttpServer::new(move || {
|
||||||
|
Loading…
Reference in New Issue
Block a user