Add support for Afero filesystems

This commit is contained in:
Matthieu Grieger 2016-08-05 00:24:49 -07:00 committed by Bjørn Erik Pedersen
parent 5619c0edbe
commit 4cf0bd2789
2 changed files with 6 additions and 4 deletions

View file

@ -77,7 +77,7 @@ func absPathify(inPath string) string {
// Check if File / Directory Exists
func exists(path string) (bool, error) {
_, err := os.Stat(path)
_, err := fs.Stat(path)
if err == nil {
return true, nil
}

View file

@ -23,7 +23,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
@ -33,15 +32,18 @@ import (
"github.com/fsnotify/fsnotify"
"github.com/mitchellh/mapstructure"
"github.com/spf13/afero"
"github.com/spf13/cast"
jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/pflag"
)
var v *Viper
var fs afero.Fs
func init() {
v = New()
fs = afero.NewOsFs()
}
type remoteConfigFactory interface {
@ -936,7 +938,7 @@ func (v *Viper) ReadInConfig() error {
return UnsupportedConfigError(v.getConfigType())
}
file, err := ioutil.ReadFile(v.getConfigFile())
file, err := afero.ReadFile(fs, v.getConfigFile())
if err != nil {
return err
}
@ -954,7 +956,7 @@ func (v *Viper) MergeInConfig() error {
return UnsupportedConfigError(v.getConfigType())
}
file, err := ioutil.ReadFile(v.getConfigFile())
file, err := afero.ReadFile(fs, v.getConfigFile())
if err != nil {
return err
}