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

Add properties and env vars resolution #89

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ngaggi73
Copy link

@ngaggi73 ngaggi73 commented Dec 2, 2024

Changes Description

Added the possibility to resolve values from other properties or environment variables using the placeholder ${<variable/property name>?(:)}.

During the unmarshalling of a configuration into a struct each property value is checked to find the presence of placeholders as the one showed above. Each placeholder is then substituted by the corresponding value of the property or environment variable, if defined, or the default value if specified. Otherwise the placeholder is left untouched.

For example the property value mongo://user:password@${mongo.database.host:localhost} will be resolved in

  • mongo://user:password@mongodb if the property mongo.database.host is defined and its value is 'mongodb'
  • mongo://user:password@localhost if the property isn't defined

If there's no default value and the referenced property isn't defined the expression is left untouched.

Associated Issues

No conversion can be done on default values

Affected Files

configuration.go
configuration_test.go

Unit Tests Changed or Added

Added environment variables and properties resolution test case to TestSource_Unmarshal function in configuration_test.go

@ngaggi73 ngaggi73 requested a review from Piszmog as a code owner December 2, 2024 11:27
Copy link
Owner

@Piszmog Piszmog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution. Please revert the package name paths. You changed Piszmog to your username

@Piszmog
Copy link
Owner

Piszmog commented Dec 3, 2024

Also, please elaborate further in the description of the PR. Provide documentation, examples, etc... The current description of the PR does not tell me what is going on, why this is an issue, and the different scenarios you would expect to see.

Copy link

sonarcloud bot commented Dec 3, 2024

@ngaggi73
Copy link
Author

ngaggi73 commented Dec 3, 2024 via email

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.

2 participants