@@ -43,6 +43,8 @@ type ConfigProvider interface {
43
43
ViaNacos (endpoints , namespaceID , groupName , dataID string , clientCfg ... constant.ClientConfig ) Parser
44
44
}
45
45
46
+ var _ ConfigProvider = & configImpl {}
47
+
46
48
// ViaFile 通过文件操作配置
47
49
func (ci * configImpl ) ViaFile (filename string ) Parser {
48
50
content , err := utils .File ().GetContents (filename )
@@ -142,12 +144,19 @@ func (ci *configImpl) ViaNacos(endpoints, namespaceID, groupName, dataID string,
142
144
if err != nil && ci .panicWhileErr {
143
145
panic (err )
144
146
}
145
- content , err := client .GetConfig (vo.ConfigParam {
146
- DataId : dataID ,
147
- Group : groupName ,
148
- })
149
- if err != nil && ci .panicWhileErr {
150
- panic (err )
147
+ if client == nil && ci .panicWhileErr {
148
+ panic ("client is nil" )
149
+ }
150
+ var content []byte
151
+ if client != nil {
152
+ data , err := client .GetConfig (vo.ConfigParam {
153
+ DataId : dataID ,
154
+ Group : groupName ,
155
+ })
156
+ content = []byte (data )
157
+ if err != nil && ci .panicWhileErr {
158
+ panic (err )
159
+ }
151
160
}
152
161
153
162
//当监听函数被设置时,需要执行监听
@@ -163,7 +172,7 @@ func (ci *configImpl) ViaNacos(endpoints, namespaceID, groupName, dataID string,
163
172
})
164
173
}
165
174
166
- return & parserImpl {content : [] byte ( content ) }
175
+ return & parserImpl {content : content }
167
176
}
168
177
169
178
// parserImpl 解析器实现
@@ -177,6 +186,9 @@ type Parser interface {
177
186
Parse (fn func (content []byte , viaWatch bool ))
178
187
}
179
188
189
+ var _ Parser = & parserImpl {}
190
+
191
+ // Parse 解析处理函数
180
192
func (pi * parserImpl ) Parse (fn func (content []byte , viaWatch bool )) {
181
193
if fn != nil {
182
194
fn (pi .content , false )
0 commit comments