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

Users should be able to set Default value in the configs #11

Closed
wgarunap opened this issue Jan 12, 2025 · 2 comments
Closed

Users should be able to set Default value in the configs #11

wgarunap opened this issue Jan 12, 2025 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@wgarunap
Copy link
Owner

wgarunap commented Jan 12, 2025

Currently users cannot set default values for env configs. if would be nice if users can add a default values to the configs.

Example

type Conf struct {
	Host string `env:"HOST" default:"localhost:8080"`
}
@wgarunap wgarunap added enhancement New feature or request good first issue Good for newcomers labels Jan 12, 2025
@wgarunap wgarunap pinned this issue Jan 13, 2025
@coderx31
Copy link
Collaborator

coderx31 commented Jan 14, 2025

Struct tags such as envDefault are used to specify default values for fields. These values are automatically applied if the corresponding environment variable is not set.
Example

type Config struct {
	Name     string `env:"MY_NAME" validate:"required"`
	Team     string `env:"MY_TEAM" envDefault:"Backend"`
	Username string `env:"MY_USERNAME" secret:"true" validate:"required"`
	Password string `env:"MY_PASSWORD" secret:"true" validate:"required"`
}

@wgarunap
Copy link
Owner Author

@coderx31 Thanks for pointing it out. Then we only have to update the documentation and the examples. Users should be aware about these features and we can utilize this issue to track the documentation update.

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

No branches or pull requests

2 participants