Skip to content

Commit

Permalink
Merge pull request #1 from offen/file_variables
Browse files Browse the repository at this point in the history
Allow override of lookup env
  • Loading branch information
MaxJa4 authored Aug 29, 2023
2 parents 10e87fe + 86e2e5b commit 6d65ebe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions envconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ type Setter interface {
Set(value string) error
}

// `os.Getenv` cannot differentiate between an explicitly set empty value
// and an unset value. `os.LookupEnv` is preferred to `syscall.Getenv`,
// but it is only available in go1.5 or newer. We're using Go build tags
// here to use os.LookupEnv for >=go1.5
// LookupEnv is a function that retrieves the value of the environment variable
var Lookup func(string) (string, bool) = lookupEnv

func (e *ParseError) Error() string {
return fmt.Sprintf("envconfig.Process: assigning %[1]s to %[2]s: converting '%[3]s' to type %[4]s. details: %[5]s", e.KeyName, e.FieldName, e.Value, e.TypeName, e.Err)
}
Expand Down Expand Up @@ -186,13 +193,9 @@ func Process(prefix string, spec interface{}) error {

for _, info := range infos {

// `os.Getenv` cannot differentiate between an explicitly set empty value
// and an unset value. `os.LookupEnv` is preferred to `syscall.Getenv`,
// but it is only available in go1.5 or newer. We're using Go build tags
// here to use os.LookupEnv for >=go1.5
value, ok := lookupEnv(info.Key)
value, ok := Lookup(info.Key)
if !ok && info.Alt != "" {
value, ok = lookupEnv(info.Alt)
value, ok = Lookup(info.Alt)
}

def := info.Tags.Get("default")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module github.com/kelseyhightower/envconfig
module github.com/offen/envconfig

0 comments on commit 6d65ebe

Please sign in to comment.