@@ -45,6 +45,10 @@ func getConfigurationFileWithENVPrefix(file, env string) (string, error) {
45
45
func (configor * Configor ) getConfigurationFiles (files ... string ) []string {
46
46
var results []string
47
47
48
+ if configor .Config .Debug || configor .Config .Verbose {
49
+ fmt .Printf ("Current environment: '%v'\n " , configor .GetEnvironment ())
50
+ }
51
+
48
52
for i := len (files ) - 1 ; i >= 0 ; i -- {
49
53
foundFile := false
50
54
file := files [i ]
@@ -106,7 +110,7 @@ func getPrefixForStruct(prefixes []string, fieldStruct *reflect.StructField) []s
106
110
return append (prefixes , fieldStruct .Name )
107
111
}
108
112
109
- func processTags (config interface {}, prefixes ... string ) error {
113
+ func ( configor * Configor ) processTags (config interface {}, prefixes ... string ) error {
110
114
configValue := reflect .Indirect (reflect .ValueOf (config ))
111
115
if configValue .Kind () != reflect .Struct {
112
116
return errors .New ("invalid config, should be struct" )
@@ -132,9 +136,16 @@ func processTags(config interface{}, prefixes ...string) error {
132
136
envNames = []string {envName }
133
137
}
134
138
139
+ if configor .Config .Verbose {
140
+ fmt .Printf ("Trying to load struct `%v`'s field `%v` from env %v\n " , configType .Name (), fieldStruct .Name , strings .Join (envNames , ", " ))
141
+ }
142
+
135
143
// Load From Shell ENV
136
144
for _ , env := range envNames {
137
145
if value := os .Getenv (env ); value != "" {
146
+ if configor .Config .Debug || configor .Config .Verbose {
147
+ fmt .Printf ("Loading configuration for struct `%v`'s field `%v` from env %v...\n " , configType .Name (), fieldStruct .Name , env )
148
+ }
138
149
if err := yaml .Unmarshal ([]byte (value ), field .Addr ().Interface ()); err != nil {
139
150
return err
140
151
}
@@ -159,15 +170,15 @@ func processTags(config interface{}, prefixes ...string) error {
159
170
}
160
171
161
172
if field .Kind () == reflect .Struct {
162
- if err := processTags (field .Addr ().Interface (), getPrefixForStruct (prefixes , & fieldStruct )... ); err != nil {
173
+ if err := configor . processTags (field .Addr ().Interface (), getPrefixForStruct (prefixes , & fieldStruct )... ); err != nil {
163
174
return err
164
175
}
165
176
}
166
177
167
178
if field .Kind () == reflect .Slice {
168
179
for i := 0 ; i < field .Len (); i ++ {
169
180
if reflect .Indirect (field .Index (i )).Kind () == reflect .Struct {
170
- if err := processTags (field .Index (i ).Addr ().Interface (), append (getPrefixForStruct (prefixes , & fieldStruct ), fmt .Sprint (i ))... ); err != nil {
181
+ if err := configor . processTags (field .Index (i ).Addr ().Interface (), append (getPrefixForStruct (prefixes , & fieldStruct ), fmt .Sprint (i ))... ); err != nil {
171
182
return err
172
183
}
173
184
}
0 commit comments