-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviper.patch
More file actions
93 lines (88 loc) · 2.63 KB
/
Copy pathviper.patch
File metadata and controls
93 lines (88 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
diff --git a/viper.go b/viper.go
index e9966ba..c904699 100644
--- a/viper.go
+++ b/viper.go
@@ -24,6 +24,7 @@ import (
"encoding/csv"
"encoding/json"
"fmt"
+ "errors"
"io"
"log"
"os"
@@ -389,7 +390,6 @@ func (v *Viper) AddRemoteProvider(provider, endpoint, path string) error {
}
return nil
}
-
// AddSecureRemoteProvider adds a remote configuration source.
// Secure Remote Providers are searched in the order they are added.
// provider is a string value, "etcd" or "consul" are currently supported.
@@ -1497,8 +1497,8 @@ func (v *Viper) WatchRemoteConfig() error {
return v.watchKeyValueConfig()
}
-func (v *Viper) WatchRemoteConfigOnChannel() error {
- return v.watchKeyValueConfigOnChannel()
+func (v *Viper) WatchRemoteConfigOnChannel(configChanged chan<- bool) error {
+ return v.watchKeyValueConfigOnChannel(configChanged)
}
func (v *Viper) insensitiviseMaps() {
@@ -1534,8 +1534,19 @@ func (v *Viper) getRemoteConfig(provider RemoteProvider) (map[string]interface{}
return v.kvstore, err
}
+func (v *Viper)GetRemoteConf() (io.Reader, error) {
+ for _, rp := range v.remoteProviders {
+ reader, err := RemoteConfig.Get(rp)
+ if err != nil {
+ continue
+ }
+ return reader, nil
+ }
+ return nil, errors.New("Did not find Remote config")
+}
+
// Retrieve the first found remote configuration.
-func (v *Viper) watchKeyValueConfigOnChannel() error {
+func (v *Viper) watchKeyValueConfigOnChannel(configChanged chan<- bool) error {
for _, rp := range v.remoteProviders {
respc, _ := RemoteConfig.WatchChannel(rp)
//Todo: Add quit channel
@@ -1544,6 +1555,7 @@ func (v *Viper) watchKeyValueConfigOnChannel() error {
b := <-rc
reader := bytes.NewReader(b.Value)
v.unmarshalReader(reader, v.kvstore)
+ configChanged <- true
}
}(respc)
return nil
@@ -1700,6 +1712,10 @@ func (v *Viper) SetConfigType(in string) {
}
}
+func (v *Viper) GetConfigType() string {
+ return v.getConfigType()
+}
+
func (v *Viper) getConfigType() string {
if v.configType != "" {
return v.configType
@@ -1719,6 +1735,21 @@ func (v *Viper) getConfigType() string {
return ""
}
+func (v *Viper) GetAppConfigFile() (string, error) {
+ if v.configFile == "" {
+ cf, err := v.findConfigFile()
+ if err != nil {
+ return "", err
+ }
+ v.configFile = cf
+ }
+ return v.configFile, nil
+}
+/*
+func (v *Viper)GetConfigFile(string, error){
+ return v.getConfigFile()
+}
+*/
func (v *Viper) getConfigFile() (string, error) {
if v.configFile == "" {
cf, err := v.findConfigFile()