Skip to content

Commit

Permalink
Adding build tags to use os.LookupEnv in >=go1.5 (#65)
Browse files Browse the repository at this point in the history
* using build tags to allow for os.LookupEnv in >=go1.5

* swapping build tags

* changing to only use os.LookupEnv for appengine
  • Loading branch information
jprobinson authored and teepark committed Oct 19, 2016
1 parent 13674b2 commit 9aca109
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
7 changes: 7 additions & 0 deletions env_os.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build appengine

package envconfig

import "os"

var lookupEnv = os.LookupEnv
7 changes: 7 additions & 0 deletions env_syscall.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build !appengine

package envconfig

import "syscall"

var lookupEnv = syscall.Getenv
8 changes: 4 additions & 4 deletions envconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"reflect"
"strconv"
"strings"
"syscall"
"time"
)

Expand Down Expand Up @@ -107,11 +106,12 @@ func Process(prefix string, spec interface{}) 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.
value, ok := syscall.Getenv(key)
// 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(key)
if !ok && alt != "" {
key := strings.ToUpper(fieldName)
value, ok = syscall.Getenv(key)
value, ok = lookupEnv(key)
}

def := ftype.Tag.Get("default")
Expand Down

0 comments on commit 9aca109

Please sign in to comment.