New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PLATFORM-1078]: Add explicit support for country metadata #55
[PLATFORM-1078]: Add explicit support for country metadata #55
Conversation
|
I feel like making the country an I'll start tackling the env thing |
actually maybe we can just require country to be set in the constructor? It will be a breaking change we actually care about but I think that every service having a name and a country isn't too big of a requirement |
44695be
to
788612d
Compare
|
Since it's technically breaking anyway, I tried refactoring things a bit I'm not completely convinced of the |
src/config/mod.rs
Outdated
| } | ||
|
|
||
| /// Try to load `country` from the `COUNTRY` environment variable | ||
| pub fn load_country(mut self) -> 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.
These load_ functions seem a little like they're doing too much - most apps will have their own way to load environment variables into a config struct, or from a file, or something, and ideally we don't need to provide it at all
If we are providing it, panicking is surprising to me - this is library code, so maybe returning a Result<Self, Self>, where in the Err side is the unmodified builder and the Ok side is the modified, would be best?
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.
Agreed, we talked about reading this stuff from env but now that I've implemented it I'm not so sure
I thought about using Result but I don't like that it kinda breaks the builder pattern, I like the idea of the type state more honestly
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 mean even with a type-state approach, fallible operations are still fallible, and my view is that fallible operations in library code should return a result (with type-state approaches it would just be a Result<Builder<WithCountry>, Builder<WithoutCountry>>, for example)
I'm not totally against it, but if it does panic you /really/ need to mention that it does, and why, in the doc comment
|
It turns out that using types instead of phantom types is good! (see: https://www.greyblake.com/blog/builder-with-typestate-in-rust/) This has escalated quickly, but we now have required the environment and the country, which unfortunately is a breaking change. I removed the load functions because I don't really like a builder which reads from env, the users can do it and try to parse the country using |
|
I tried the typed builder create but it doesn't fully support "pre-setting" certain parameters (i.e. the formatter). Once you set something you can't set it anymore I tried setting the formatter as an option but it makes the interface worse down the line As it stands the PR introduces the following changes
I chose not to introduce the loading from env because it doesn't seem like a responsibility of |
| #[derive(Eq, PartialEq, Debug, Clone, Copy)] | ||
| pub enum Environment { | ||
| Dev, | ||
| Qa, |
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 we still have Qa?
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.
We plan to get rid of it but for now it's still a thing
Co-authored-by: Simone Cottini <cottini.simone@gmail.com>
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.
No notes from me, I would wait to see if anyone else has anything to say
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.
LGTM ![]()
https://prima-assicurazioni-spa.myjetbrains.com/youtrack/issue/PLATFORM-1078
Add support for country