@@ -23,6 +23,8 @@ func NewViper() (Handler, error) {
23
23
24
24
v .SetDefault ("server" , server )
25
25
v .SetDefault ("mesh" , mesh )
26
+ v .SetDefault ("operations" , operations )
27
+
26
28
err := v .WriteConfig ()
27
29
if err != nil {
28
30
_ , er := os .Create (fmt .Sprintf ("%s/%s" , filepath , filename ))
@@ -37,9 +39,13 @@ func NewViper() (Handler, error) {
37
39
}
38
40
39
41
// SetKey sets a key value in viper
40
- func (v * Viper ) SetKey (key string , value string ) {
42
+ func (v * Viper ) SetKey (key string , value string ) error {
41
43
v .instance .Set (key , value )
42
- _ = v .instance .WriteConfig ()
44
+ err := v .instance .WriteConfig ()
45
+ if err != nil {
46
+ return ErrViper (err )
47
+ }
48
+ return nil
43
49
}
44
50
45
51
// GetKey gets a key value from viper
@@ -68,28 +74,21 @@ func (v *Viper) Server(result interface{}) error {
68
74
}
69
75
70
76
// MeshSpec provides mesh specific configuration
71
- func (v * Viper ) MeshSpec (result interface {}) error {
72
- err := v .instance . ReadInConfig ( )
77
+ func (v * Viper ) Mesh (result interface {}) error {
78
+ s , err := v .GetKey ( "mesh" )
73
79
if err != nil {
74
80
return ErrViper (err )
75
81
}
76
- return v .instance .Unmarshal (& result )
77
- }
78
82
79
- // MeshInstance provides mesh specific configuration
80
- func (v * Viper ) MeshInstance (result interface {}) error {
81
- err := v .instance .ReadInConfig ()
82
- if err != nil {
83
- return ErrViper (err )
84
- }
85
- return v .instance .Unmarshal (& result )
83
+ return utils .Unmarshal (s , & result )
86
84
}
87
85
88
86
// Operations provides list of operations available
89
87
func (v * Viper ) Operations (result interface {}) error {
90
- err := v .instance . ReadInConfig ( )
88
+ s , err := v .GetKey ( "operations" )
91
89
if err != nil {
92
90
return ErrViper (err )
93
91
}
94
- return v .instance .Unmarshal (& result )
92
+
93
+ return utils .Unmarshal (s , & result )
95
94
}
0 commit comments