Skip to content

Commit

Permalink
new reader auto fallback to env
Browse files Browse the repository at this point in the history
  • Loading branch information
acoshift committed Sep 2, 2019
1 parent 345a4e3 commit ee3a946
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ before_install:
- go get github.com/mattn/goveralls

env:
- GO111MODULE=on DATA1=true DATA2=false DATA3=9 DATA4=0 DATA5=3m5s EMPTY="" DATA6="aGVsbG8="
- GO111MODULE=on DATA1=true DATA2=false DATA3=9 DATA4=0 DATA5=3m5s EMPTY="" DATA6="aGVsbG8=" ONLYENV=1

script:
- $HOME/gopath/bin/goveralls -service=travis-ci
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ test:
DATA5=3m5s \
DATA6="aGVsbG8=" \
EMPTY="" \
ONLYENV=1 \
go test ./...
4 changes: 2 additions & 2 deletions configfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ func NewReader(base string) *Reader {
stats, _ := os.Stat(base)
if stats != nil {
if stats.IsDir() {
return NewDirReader(base)
return NewDirReader(base).Fallback(NewEnvReader())
}
return NewYAMLReader(base)
return NewYAMLReader(base).Fallback(NewEnvReader())
}
return NewEnvReader()
}
Expand Down
2 changes: 2 additions & 0 deletions configfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,4 +479,6 @@ func TestFallback(t *testing.T) {
t.Parallel()

testReader(t, configfile.NewDirReader("notexists").Fallback(configfile.NewEnvReader()))

assert.Equal(t, 1, configfile.NewReader("testdata/config.yaml").Int("ONLYENV"))
}

0 comments on commit ee3a946

Please sign in to comment.