blob: e6cd0bd27eaafe218231ed50d15a6fd83cf187da (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
pub use config::ConfigError;
use deadpool_postgres::Pool;
use serde::Deserialize;
use slog::{o, Drain, Logger};
use slog_async;
use slog_term;
#[derive(Deserialize)]
pub struct ServerConfig {
pub host: String,
pub port: u16,
}
#[derive(Deserialize)]
pub struct Config {
pub server: ServerConfig,
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()
}
pub fn logging() -> Logger {
let decorator = slog_term::TermDecorator::new().build();
let drain = slog_term::FullFormat::new(decorator).build().fuse();
let drain = slog_async::Async::new(drain).build().fuse();
slog::Logger::root(drain, o!())
}
}
#[derive(Clone)]
pub struct AppState {
pub pool: Pool,
pub log: slog::Logger,
}
|