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`. 💡 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: Example setting environment variables:
```go ```go
os.Setenv("ORMUS_DEBUG", "true") os.Setenv("EB_DEBUG", "true")
os.Setenv("ORMUS_MULTI_WORD_VAR", "this is a multi-word var") os.Setenv("EB_MULTI_WORD_VAR", "this is a multi-word var")
// ... set other environment variables ... // ... set other environment variables ...
``` ```
@ -44,7 +44,7 @@ Example `config.yml` file:
debug: true debug: true
multi_word_var: "this is a multi-word var in YAML" multi_word_var: "this is a multi-word var in YAML"
db: db:
username: ormus username: eb
password: youcannotbreakme password: youcannotbreakme
# ... other configurations ... # ... other configurations ...
``` ```

View File

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

View File

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