Add support for Afero filesystems
diff --git a/util.go b/util.go
index 3c4a320..6b34e14 100644
--- a/util.go
+++ b/util.go
@@ -77,7 +77,7 @@
// 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
}
diff --git a/viper.go b/viper.go
index d800395..ba3c190 100644
--- a/viper.go
+++ b/viper.go
@@ -23,7 +23,6 @@
"bytes"
"fmt"
"io"
- "io/ioutil"
"log"
"os"
"path/filepath"
@@ -33,15 +32,18 @@
"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 @@
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 @@
return UnsupportedConfigError(v.getConfigType())
}
- file, err := ioutil.ReadFile(v.getConfigFile())
+ file, err := afero.ReadFile(fs, v.getConfigFile())
if err != nil {
return err
}