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

Nested Prefixing #5

Merged
merged 5 commits into from
Jul 18, 2024
Merged

Nested Prefixing #5

merged 5 commits into from
Jul 18, 2024

Conversation

syntaqx
Copy link
Owner

@syntaqx syntaqx commented Jul 17, 2024

Allows for optional nested prefixes

type DatabaseConfig struct {
    Host     string `env:"HOST,default=localhost"`
    Port     int    `env:"PORT|DB_PORT,fallback=3306"`
    Username string `env:"USERNAME,default=root"`
    Password string `env:"PASSWORD,required"`
    Database string `env:"NAME"`
}

type Config struct {
    Database  DatabaseConfig `env:"DATABASE"`
}

Or

type DatabaseConfig struct {
    Host     string `env:"DATABASE_HOST,default=localhost"`
    Port     int    `env:"DATABASE_PORT|DB_PORT,fallback=3306"`
    Username string `env:"DATABASE_USERNAME,default=root"`
    Password string `env:"DATABASE_PASSWORD,required"`
    Database string `env:"DATABASE_NAME"`
}

type Config struct {
    Database  DatabaseConfig
}

To both work as expected.

Copy link

codecov bot commented Jul 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (579857a) to head (3dddaf1).

Additional details and impacted files
@@            Coverage Diff            @@
##              main        #5   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          126       138   +12     
=========================================
+ Hits           126       138   +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@syntaqx syntaqx marked this pull request as draft July 17, 2024 23:50
@syntaqx syntaqx linked an issue Jul 17, 2024 that may be closed by this pull request
@syntaqx syntaqx marked this pull request as ready for review July 18, 2024 00:19
@syntaqx syntaqx merged commit 577c2ff into main Jul 18, 2024
5 checks passed
@syntaqx syntaqx deleted the nested-prefix branch July 18, 2024 00:31
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

Successfully merging this pull request may close these issues.

Are you open for code review?
1 participant