Skip to content

Commit 91c787a

Browse files
author
Veniamin Albaev
committed
Rename new option
1 parent c4030ea commit 91c787a

2 files changed

Lines changed: 30 additions & 30 deletions

File tree

envconfig.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var (
2626
type context struct {
2727
name string
2828
prefix string
29-
prefixTag bool
29+
prefixCustomNames bool
3030
customName string
3131
defaultVal string
3232
usingDefault bool
@@ -46,8 +46,8 @@ type Options struct {
4646
// Prefix allows specifying a prefix for each key.
4747
Prefix string
4848

49-
// PrefixTag enables prefixes for the custom names set via struct tags
50-
PrefixTag bool
49+
// PrefixCustomNames enables prefixes for the custom names set via struct tags
50+
PrefixCustomNames bool
5151

5252
// AllOptional determines whether to not throw errors by default for any key
5353
// that is not found. AllOptional=true means errors will not be thrown.
@@ -101,12 +101,12 @@ func InitWithOptions(conf interface{}, opts Options) error {
101101
elem := value.Elem()
102102

103103
ctx := context{
104-
name: opts.Prefix,
105-
prefix: opts.Prefix,
106-
prefixTag: opts.PrefixTag,
107-
optional: opts.AllOptional,
108-
leaveNil: opts.LeaveNil,
109-
allowUnexported: opts.AllowUnexported,
104+
name: opts.Prefix,
105+
prefix: opts.Prefix,
106+
prefixCustomNames: opts.PrefixCustomNames,
107+
optional: opts.AllOptional,
108+
leaveNil: opts.LeaveNil,
109+
allowUnexported: opts.AllowUnexported,
110110
}
111111
switch elem.Kind() {
112112
case reflect.Ptr:
@@ -182,28 +182,28 @@ func readStruct(value reflect.Value, ctx *context) (nonNil bool, err error) {
182182
case field.Kind() == reflect.Struct && !isUnmarshaler(fieldType):
183183
var nonNilIn bool
184184
nonNilIn, err = readStruct(field, &context{
185-
name: combineName(ctx.name, name),
186-
prefix: ctx.prefix,
187-
prefixTag: ctx.prefixTag,
188-
optional: ctx.optional || tag.optional,
189-
defaultVal: tag.defaultVal,
190-
parents: parents,
191-
leaveNil: ctx.leaveNil,
192-
allowUnexported: ctx.allowUnexported,
185+
name: combineName(ctx.name, name),
186+
prefix: ctx.prefix,
187+
prefixCustomNames: ctx.prefixCustomNames,
188+
optional: ctx.optional || tag.optional,
189+
defaultVal: tag.defaultVal,
190+
parents: parents,
191+
leaveNil: ctx.leaveNil,
192+
allowUnexported: ctx.allowUnexported,
193193
})
194194
nonNil = nonNil || nonNilIn
195195
default:
196196
var ok bool
197197
ok, err = setField(field, &context{
198-
name: combineName(ctx.name, name),
199-
prefix: ctx.prefix,
200-
prefixTag: ctx.prefixTag,
201-
customName: tag.customName,
202-
optional: ctx.optional || tag.optional,
203-
defaultVal: tag.defaultVal,
204-
parents: parents,
205-
leaveNil: ctx.leaveNil,
206-
allowUnexported: ctx.allowUnexported,
198+
name: combineName(ctx.name, name),
199+
prefix: ctx.prefix,
200+
prefixCustomNames: ctx.prefixCustomNames,
201+
customName: tag.customName,
202+
optional: ctx.optional || tag.optional,
203+
defaultVal: tag.defaultVal,
204+
parents: parents,
205+
leaveNil: ctx.leaveNil,
206+
allowUnexported: ctx.allowUnexported,
207207
})
208208
nonNil = nonNil || ok
209209
}
@@ -471,7 +471,7 @@ func readValue(ctx *context) (string, error) {
471471

472472
func makeAllPossibleKeys(ctx *context) (res []string) {
473473
if ctx.customName != "" {
474-
if ctx.prefixTag {
474+
if ctx.prefixCustomNames {
475475
return []string{ctx.prefix + "_" + ctx.customName}
476476
}
477477
return []string{ctx.customName}

envconfig_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ func TestInitWithPrefix(t *testing.T) {
652652
TestEnvNodeBar1: "D1",
653653
},
654654
}
655-
655+
656656
require.NoError(t, os.Setenv("TEST_ENV_FOO1", expect.TestEnvFoo1))
657657
require.NoError(t, os.Setenv("TESTPREFIX1_TEST_ENV_BAR1", expect.TestEnvBar1))
658658
require.NoError(t, os.Setenv("TEST_ENV_NODE_FOO1", expect.Node1.TestEnvNodeFoo1))
@@ -693,8 +693,8 @@ func TestInitWithPrefix(t *testing.T) {
693693

694694
var conf Root2
695695
err := envconfig.InitWithOptions(&conf, envconfig.Options{
696-
Prefix: "TESTPREFIX2",
697-
PrefixTag: true,
696+
Prefix: "TESTPREFIX2",
697+
PrefixCustomNames: true,
698698
})
699699

700700
require.NoError(t, err)

0 commit comments

Comments
 (0)