forked from mirror/viper
Add support for Afero filesystems
This commit is contained in:
parent
5619c0edbe
commit
4cf0bd2789
2
util.go
2
util.go
|
@ -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
|
||||
}
|
||||
|
|
8
viper.go
8
viper.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue