[#493] node/config: Implement ENV variable key constructor

Add `internal.Env` function which converts path to config value to ENV
variable key.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-21 20:40:43 +03:00 committed by Leonard Lyubich
parent 270b147205
commit 099ceeae50
2 changed files with 29 additions and 0 deletions

View file

@ -1,8 +1,22 @@
package internal package internal
import (
"strings"
)
// EnvPrefix is a prefix of ENV variables related // EnvPrefix is a prefix of ENV variables related
// to storage node configuration. // to storage node configuration.
const EnvPrefix = "neofs" const EnvPrefix = "neofs"
// EnvSeparator is a section separator in ENV variables. // EnvSeparator is a section separator in ENV variables.
const EnvSeparator = "_" const EnvSeparator = "_"
// Env returns ENV variable key for particular config parameter.
func Env(path ...string) string {
return strings.ToUpper(
strings.Join(
append([]string{EnvPrefix}, path...),
EnvSeparator,
),
)
}

View file

@ -0,0 +1,15 @@
package internal_test
import (
"testing"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/internal"
"github.com/stretchr/testify/require"
)
func TestEnv(t *testing.T) {
require.Equal(t,
"NEOFS_SECTION_PARAMETER",
internal.Env("section", "parameter"),
)
}