mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
Export and fix GetConfigFile
This commit is contained in:
parent
aafc9e6bc7
commit
00ed41cdba
3 changed files with 16 additions and 21 deletions
|
@ -1 +0,0 @@
|
||||||
QProcess::start: Process is already running
|
|
24
viper.go
24
viper.go
|
@ -268,7 +268,7 @@ func (v *Viper) WatchConfig() {
|
||||||
defer watcher.Close()
|
defer watcher.Close()
|
||||||
|
|
||||||
// we have to watch the entire directory to pick up renames/atomic saves in a cross-platform way
|
// we have to watch the entire directory to pick up renames/atomic saves in a cross-platform way
|
||||||
filename, err := v.getConfigFile()
|
filename, err := v.GetConfigFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error:", err)
|
log.Println("error:", err)
|
||||||
return
|
return
|
||||||
|
@ -1131,7 +1131,7 @@ func (v *Viper) Set(key string, value interface{}) {
|
||||||
func ReadInConfig() error { return v.ReadInConfig() }
|
func ReadInConfig() error { return v.ReadInConfig() }
|
||||||
func (v *Viper) ReadInConfig() error {
|
func (v *Viper) ReadInConfig() error {
|
||||||
jww.INFO.Println("Attempting to read in config file")
|
jww.INFO.Println("Attempting to read in config file")
|
||||||
filename, err := v.getConfigFile()
|
filename, err := v.GetConfigFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1161,7 +1161,7 @@ func (v *Viper) ReadInConfig() error {
|
||||||
func MergeInConfig() error { return v.MergeInConfig() }
|
func MergeInConfig() error { return v.MergeInConfig() }
|
||||||
func (v *Viper) MergeInConfig() error {
|
func (v *Viper) MergeInConfig() error {
|
||||||
jww.INFO.Println("Attempting to merge in config file")
|
jww.INFO.Println("Attempting to merge in config file")
|
||||||
filename, err := v.getConfigFile()
|
filename, err := v.GetConfigFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1203,7 +1203,7 @@ func (v *Viper) MergeConfig(in io.Reader) error {
|
||||||
// WriteConfig writes the current configuration to a file.
|
// WriteConfig writes the current configuration to a file.
|
||||||
func WriteConfig() error { return v.WriteConfig() }
|
func WriteConfig() error { return v.WriteConfig() }
|
||||||
func (v *Viper) WriteConfig() error {
|
func (v *Viper) WriteConfig() error {
|
||||||
filename, err := v.getConfigFile()
|
filename, err := v.GetConfigFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1213,7 +1213,7 @@ func (v *Viper) WriteConfig() error {
|
||||||
// SafeWriteConfig writes current configuration to file only if the file does not exist.
|
// SafeWriteConfig writes current configuration to file only if the file does not exist.
|
||||||
func SafeWriteConfig() error { return v.SafeWriteConfig() }
|
func SafeWriteConfig() error { return v.SafeWriteConfig() }
|
||||||
func (v *Viper) SafeWriteConfig() error {
|
func (v *Viper) SafeWriteConfig() error {
|
||||||
filename, err := v.getConfigFile()
|
filename, err := v.GetConfigFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1705,7 +1705,7 @@ func (v *Viper) getConfigType() string {
|
||||||
return v.configType
|
return v.configType
|
||||||
}
|
}
|
||||||
|
|
||||||
cf, err := v.getConfigFile()
|
cf, err := v.GetConfigFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -1719,19 +1719,15 @@ func (v *Viper) getConfigType() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Viper) getConfigFile() (string, error) {
|
func (v *Viper) GetConfigFile() (string, error) {
|
||||||
// if explicitly set, then use it
|
if v.configFile == "" {
|
||||||
if v.configFile != "" {
|
|
||||||
return v.configFile, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
cf, err := v.findConfigFile()
|
cf, err := v.findConfigFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
v.configFile = cf
|
v.configFile = cf
|
||||||
return v.getConfigFile()
|
}
|
||||||
|
return v.configFile, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Viper) searchInPath(in string) (filename string) {
|
func (v *Viper) searchInPath(in string) (filename string) {
|
||||||
|
|
|
@ -244,7 +244,7 @@ func (s *stringValue) String() string {
|
||||||
|
|
||||||
func TestBasics(t *testing.T) {
|
func TestBasics(t *testing.T) {
|
||||||
SetConfigFile("/tmp/config.yaml")
|
SetConfigFile("/tmp/config.yaml")
|
||||||
filename, err := v.getConfigFile()
|
filename, err := v.GetConfigFile()
|
||||||
assert.Equal(t, "/tmp/config.yaml", filename)
|
assert.Equal(t, "/tmp/config.yaml", filename)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
@ -1177,7 +1177,7 @@ func TestUnmarshalingWithAliases(t *testing.T) {
|
||||||
func TestSetConfigNameClearsFileCache(t *testing.T) {
|
func TestSetConfigNameClearsFileCache(t *testing.T) {
|
||||||
SetConfigFile("/tmp/config.yaml")
|
SetConfigFile("/tmp/config.yaml")
|
||||||
SetConfigName("default")
|
SetConfigName("default")
|
||||||
f, err := v.getConfigFile()
|
f, err := v.GetConfigFile()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("config file cache should have been cleared")
|
t.Fatalf("config file cache should have been cleared")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue