mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
Add support for Afero filesystems
This commit is contained in:
parent
5619c0edbe
commit
4cf0bd2789
2 changed files with 6 additions and 4 deletions
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 a new issue