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

Comments for env prefix constants + minor refactoring #139

Merged
merged 2 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions conf/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ import (
)

const (
// configFileEnvVariableName is name of environment variable that
// contains name of configuration file
configFileEnvVariableName = "INSIGHTS_RESULTS_SMART_PROXY_CONFIG_FILE"

// envPrefix is prefix for all environment variables that contains
// various configuration options
envPrefix = "INSIGHTS_RESULTS_SMART_PROXY_"
)

// SetupConfiguration should only be used at startup
Expand Down Expand Up @@ -111,9 +117,6 @@ func LoadConfiguration(defaultConfigFile string) error {
}

// override config from env if there's variable in env

const envPrefix = "INSIGHTS_RESULTS_SMART_PROXY_"

viper.AutomaticEnv()
viper.SetEnvPrefix(envPrefix)
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "__"))
Expand Down
23 changes: 18 additions & 5 deletions docs/packages/conf/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,23 @@
<div class="operator">)</div><div class="operator"></div>

<div class="keyword">const</div> <div class="operator">(</div>
<div class="ident">configFileEnvVariableName</div> <div class="operator">=</div> <div class="literal">&#34;INSIGHTS_RESULTS_SMART_PROXY_CONFIG_FILE&#34;</div><div class="operator"></div>
</code></pre></td>
</tr>

<tr class="section">
<td class="doc"><p>configFileEnvVariableName is name of environment variable that
contains name of configuration file</p>
</td>
<td class="code"><pre><code> <div class="ident">configFileEnvVariableName</div> <div class="operator">=</div> <div class="literal">&#34;INSIGHTS_RESULTS_SMART_PROXY_CONFIG_FILE&#34;</div><div class="operator"></div>

</code></pre></td>
</tr>

<tr class="section">
<td class="doc"><p>envPrefix is prefix for all environment variables that contains
various configuration options</p>
</td>
<td class="code"><pre><code> <div class="ident">envPrefix</div> <div class="operator">=</div> <div class="literal">&#34;INSIGHTS_RESULTS_SMART_PROXY_&#34;</div><div class="operator"></div>
<div class="operator">)</div><div class="operator"></div>

</code></pre></td>
Expand Down Expand Up @@ -280,10 +296,7 @@
<tr class="section">
<td class="doc"><p>override config from env if there's variable in env</p>
</td>
<td class="code"><pre><code>
<div class="keyword">const</div> <div class="ident">envPrefix</div> <div class="operator">=</div> <div class="literal">&#34;INSIGHTS_RESULTS_SMART_PROXY_&#34;</div><div class="operator"></div>

<div class="ident">viper</div><div class="operator">.</div><div class="ident">AutomaticEnv</div><div class="operator">(</div><div class="operator">)</div><div class="operator"></div>
<td class="code"><pre><code> <div class="ident">viper</div><div class="operator">.</div><div class="ident">AutomaticEnv</div><div class="operator">(</div><div class="operator">)</div><div class="operator"></div>
<div class="ident">viper</div><div class="operator">.</div><div class="ident">SetEnvPrefix</div><div class="operator">(</div><div class="ident">envPrefix</div><div class="operator">)</div><div class="operator"></div>
<div class="ident">viper</div><div class="operator">.</div><div class="ident">SetEnvKeyReplacer</div><div class="operator">(</div><div class="ident">strings</div><div class="operator">.</div><div class="ident">NewReplacer</div><div class="operator">(</div><div class="literal">&#34;-&#34;</div><div class="operator">,</div> <div class="literal">&#34;_&#34;</div><div class="operator">,</div> <div class="literal">&#34;.&#34;</div><div class="operator">,</div> <div class="literal">&#34;__&#34;</div><div class="operator">)</div><div class="operator">)</div><div class="operator"></div>

Expand Down