Skip to content
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

Use schematic for configuration #1166

Open
milesj opened this issue Jan 9, 2025 · 1 comment
Open

Use schematic for configuration #1166

milesj opened this issue Jan 9, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@milesj
Copy link

milesj commented Jan 9, 2025

Description

Big fan of this project, looking forward to its progress.

With that said, I see that you're using raw serde for configuration, and I humbly suggest using my schematic (https://moonrepo.github.io/schematic/config/index.html) crate for configuration instead. I've spent a lot of time fine tuning this crate, as it packs a ton of features. Some of these features include layering + merging + extending, default values, built-in validation, environment variables, and more.

All of this is backed by a powerful derive macro, for example:

use schematic::Config;

#[derive(Config)]
struct AppConfig {
    #[setting(default = 3000, env = "PORT")]
    pub port: usize,

    #[setting(default = true)]
    pub secure: bool,

    #[setting(default = vec!["localhost".into()])]
    pub allowed_hosts: Vec<String>,
}

On top of configuration, the crate is also provides schema modeling (https://moonrepo.github.io/schematic/schema/index.html), which is automatically generated when using the Config macro. Schemas enable powerful code generation, for example, generating TypeScript types or JSON schemas!

And lastly, if using miette, you'd get nice error messages like so:

Screenshot 2025-01-09 at 10 11 58 AM Screenshot 2025-01-09 at 10 13 26 AM

To Reproduce

N/A

Expected Behavior

N/A

Environment:

Additional Context

Open to collaborating on this if you're interested!

@jondot jondot added enhancement New feature or request controller and removed controller labels Jan 15, 2025
@kaplanelad
Copy link
Contributor

kaplanelad commented Jan 20, 2025

Hey @milesj,
Thank you for reaching out and sharing your project! It looks like a very cool.

At the moment, we don’t have any immediate issues with our current configuration setup. After reviewing the project issues/questions, I do not see user problems in this area, as the current configuration approach is working well for us.

Additionally, we aim to minimize the number of dependencies in our project to reduce compilation time, maintenance efforts, and the learning curve. We are already using serde_yaml for our configuration serialization, so for now, we’ll continue using it as it suits our needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants