-
Notifications
You must be signed in to change notification settings - Fork 3
Conversation
@alexlapa напишите, пожалуйста, какие параметры нужны в конфиге, как будут задаваться (файл, env) и значения по-умолчанию, если нужны. |
@Kirguir , В сорцах стоят дефолтные значения, переопределяются они через конфигурационный файл или через переменные среды. А вот по приоритету config / env var уже не так очевидно. Я бы вообще просто панику бросал, если одна и та-же переменная прокидывается и через конфиг и через окружение и с разными значениями. Как в SAPI было сделано? env var > config? По поводу конкретных параметров сейчас мудрить смысла не вижу - они в процессе сами будут появляться. Например, |
# Conflicts: # Cargo.lock # Cargo.toml # src/main.rs
…me, add basic makefile, add config tests, add duration serde tests
Гляньте, пожалуйста, будут ли у Вас замечания по реализации. Документацию добавлю после, и тогда уже попрошу полное ревью. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overall impression that code may be simplified.
Consider to use structopt for command line.
Wrapping into untyped config::Config
for merging is also a bit strange. Can't this be achieved without that?
Cargo.toml
Outdated
futures = "0.1" | ||
hashbrown = "0.1" | ||
humantime = "1.2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no sense to specify patch version due to work of default carret requirement.
Just humantime = "1.2"
is enough.
src/conf/mod.rs
Outdated
}; | ||
use failure::Error; | ||
use serde_derive::{Deserialize, Serialize}; | ||
use std::collections::HashMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not forget to separate std
imports .
src/conf/server.rs
Outdated
fn default() -> Self { | ||
Self { | ||
bind_ip: IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), | ||
bind_port: 8080, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider to use smart-default. It's way more ergonomic.
|
||
impl Server { | ||
pub fn get_bind_addr(&self) -> impl std::net::ToSocketAddrs { | ||
(self.bind_ip, self.bind_port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why returning impl
? It has no sense in this context. It's almost always to return a concrete type rather then it's abstraction. So, just (IpAddr, u16)
is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если можно вернуть интерфейс - нужно возвращать интерфейс. Просто хороший тон. Но, не принципиально, на самом деле.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kirguir why this is a good tone? It just erases additional type information. "Expect wider type, but return concrete type".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Абстракции, инкапсуляция, loose coupling, все дела.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexlapa hmm... I agree. I this context it allows to hide the inner representation of the Server
, which makes sense in the usage places where we require just ToSocketAddrs
.
Cargo.toml
Outdated
serde = { version = "1.0", features = ["derive"] } | ||
serde_derive = "1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add serde_derive
again when the next line above contains features = ["derive"]
?
src/conf/duration.rs
Outdated
E: de::Error, | ||
{ | ||
let dur = humantime::parse_duration(value).map_err(|_| { | ||
de::Error::invalid_value(Unexpected::Str(value), &self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, this seems tough. This should be implemented in some util
module, or even a separate crate.
Fortunately, reading documentation carefully allows to avoid writing redudant code: serde-humantime 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/conf/mod.rs
Outdated
/// - configuration file, the name of which is given as a command line | ||
/// parameter or environment variable; | ||
/// - environment variables; | ||
pub fn new() -> Result<Self, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess parse()
is a better name here.
src/api/client/server.rs
Outdated
}; | ||
|
||
use super::*; | ||
use crate::conf::server::Server; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not very ergonomic due to know how conf
module is layouted. It's better to re-export stuff in conf
, so I can just do conff::Server
.
Вы, помнится, заметили, что, вроде бы, вот этот кусок:
можно реализовать корректнее. Напомните, пожалуйста, каким образом. |
@alexlapa nope, I've investigated a However, as far as I found, we may omit let mut cfg = Config::try_from(&Self::default())?; which requires only |
Изучил |
meh... 😕 OK, now the current implementation is OK. Later, I'll fix the issue in
Agree, for now we can skip it. Changing the priorities i not the solution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- A little refactoring is done to simplify code more and make tests more BDD'ish.
- Removed unused dependencies.
- Refactored
Makefile
to throw away Docker squats.
Do not forget about FCM.
FCM:
Create application configuration (#15)
- impl conf module which holds typed configuration of application
- parse configuration from file and env vars
- allow to specify configuration file path
- refactor existing code to use values from configuration options
Implement a layer that implements the configuration of the application and provides the means to work with it.