Skip to content

Commit

Permalink
Append trailing underscore to prefixes if not present
Browse files Browse the repository at this point in the history
  • Loading branch information
athyk committed Jan 27, 2025
1 parent 8d0b592 commit 6f2f65d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions env/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,16 @@ func (opts Options) getRawEnv(s string) string {
// - A new Options struct with the prefix set.
//
// See: https://pkg.go.dev/reflect#StructField
//
// Note: If a trailing underscore is not present, it will append one.
func (opts Options) withPrefix(sf reflect.StructField) Options {
opts.Prefix = opts.Prefix + sf.Tag.Get(PrefixEnv)

// Append an underscore if it's not already there.
if len(opts.Prefix) > 0 && opts.Prefix[len(opts.Prefix)-1] != '_' {
opts.Prefix = opts.Prefix + "_"
}

return opts
}

Expand Down

0 comments on commit 6f2f65d

Please sign in to comment.