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 · 0 comments
Open

Use schematic for configuration #1166

milesj opened this issue Jan 9, 2025 · 0 comments

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!

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

No branches or pull requests

1 participant