Skip to content

Commit 6f2f65d

Browse files
committed
Append trailing underscore to prefixes if not present
1 parent 8d0b592 commit 6f2f65d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

env/options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,16 @@ func (opts Options) getRawEnv(s string) string {
8888
// - A new Options struct with the prefix set.
8989
//
9090
// See: https://pkg.go.dev/reflect#StructField
91+
//
92+
// Note: If a trailing underscore is not present, it will append one.
9193
func (opts Options) withPrefix(sf reflect.StructField) Options {
9294
opts.Prefix = opts.Prefix + sf.Tag.Get(PrefixEnv)
95+
96+
// Append an underscore if it's not already there.
97+
if len(opts.Prefix) > 0 && opts.Prefix[len(opts.Prefix)-1] != '_' {
98+
opts.Prefix = opts.Prefix + "_"
99+
}
100+
93101
return opts
94102
}
95103

0 commit comments

Comments
 (0)