Enhancing Configuration Merging and Retrieval in Viper #1839
Unanswered
guptaaashutosh
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Introduction:
As avid users of Viper, we've encountered a scenario where we need to compare keys between .env and .env.example files and ensure that values from the .env file are retained during the merging process. Despite the robust capabilities of Viper, we've faced challenges in retrieving values specifically from the .env file after merging configurations. In this discussion, we seek guidance and share our approach to address this issue.
Current Approach:
Currently, we're loading configurations from both .env and .env.example files using Viper. We then merge configurations from .env.example into .env to compare keys. However, we've noticed that values from the .env file are overwritten by values from .env.example during the merging process, leading to difficulties in retrieving .env values after merging.
Proposed Solution:
To prioritize values from the .env file during merging, we've explored using viper.MergeConfigMap() to manually merge configurations. By first storing configurations from .env in a map, merging configurations from .env.example, and then merging .env configurations into the merged result, we aim to ensure that values from .env are retained.
Beta Was this translation helpful? Give feedback.
All reactions