fix(config): change ormus to eb

This commit is contained in:
mohammad mahdi rezaei 2023-12-18 10:03:31 +03:30
parent 55206f8629
commit 8e073db3e7
3 changed files with 15 additions and 15 deletions

View File

@ -24,12 +24,12 @@ The package allows setting up configurations in three ways:
💡 Use this way for storing `important secrets` that should not be hard coded in repo or in `config.yml` file. For example, `DB_PASSWORD`, or `JWT_SECRET`.
Environment variables are used to configure the application at runtime. The variable names must start with `ORMUS_`, and nested variables should use `__` as a separator (`ORMUS_DB__HOST`).
Environment variables are used to configure the application at runtime. The variable names must start with `EB_`, and nested variables should use `__` as a separator (`EB_DB__HOST`).
Example setting environment variables:
```go
os.Setenv("ORMUS_DEBUG", "true")
os.Setenv("ORMUS_MULTI_WORD_VAR", "this is a multi-word var")
os.Setenv("EB_DEBUG", "true")
os.Setenv("EB_MULTI_WORD_VAR", "this is a multi-word var")
// ... set other environment variables ...
```
@ -44,7 +44,7 @@ Example `config.yml` file:
debug: true
multi_word_var: "this is a multi-word var in YAML"
db:
username: ormus
username: eb
password: youcannotbreakme
# ... other configurations ...
```

View File

@ -32,7 +32,7 @@ type nestedMultiWordConfig struct {
}
const (
prefix = "ORMUS_"
prefix = "EB_"
delimiter = "."
separator = "__"
)
@ -115,13 +115,13 @@ db:
func TestLoadConfigFromEnvironmentVariable(t *testing.T) {
k := koanf.New(".")
os.Setenv("ORMUS_DEBUG", "false")
os.Setenv("ORMUS_MULTI_WORD_VAR", "this is multi word var")
os.Setenv("ORMUS_DB__HOST", "localhost")
os.Setenv("ORMUS_DB__USERNAME", "hossein")
os.Setenv("ORMUS_DB__PASSWORD", "1234")
os.Setenv("ORMUS_DB__MULTI_WORD_NESTED_VAR", "testing make it easy (:")
os.Setenv("ORMUS_DB__NESTED_MULTI_WORD_CONFIG__DOWN_HERE", "im here")
os.Setenv("EB_DEBUG", "false")
os.Setenv("EB_MULTI_WORD_VAR", "this is multi word var")
os.Setenv("EB_DB__HOST", "localhost")
os.Setenv("EB_DB__USERNAME", "hossein")
os.Setenv("EB_DB__PASSWORD", "1234")
os.Setenv("EB_DB__MULTI_WORD_NESTED_VAR", "testing make it easy (:")
os.Setenv("EB_DB__NESTED_MULTI_WORD_CONFIG__DOWN_HERE", "im here")
if err := k.Load(env.Provider(prefix, delimiter, callbackEnv), nil); err != nil {
t.Logf("error loading environment variables: %s", err)

View File

@ -12,7 +12,7 @@ import (
)
const (
defaultPrefix = "ORMUS_"
defaultPrefix = "EB_"
defaultDelimiter = "."
defaultSeparator = "__"
defaultYamlFilePath = "config.yml"
@ -28,8 +28,8 @@ type Option struct {
CallbackEnv func(string) string
}
// our environment variables must prefix with `ORMUS_`
// for nested env should use `__` aka: ORMUS_DB__HOST.
// our environment variables must prefix with `EB_`
// for nested env should use `__` aka: EB__DB__HOST.
func defaultCallbackEnv(source string) string {
base := strings.ToLower(strings.TrimPrefix(source, defaultPrefix))