@@ -121,6 +121,7 @@ type Cache struct {
121
121
data sync.Map
122
122
}
123
123
124
+ // Set 将给定的键值对存储到缓存中,并根据指定的持续时间设置过期机制。
124
125
func (cache * Cache ) Set (key * openapi.Config , value interface {}, duration time.Duration ) {
125
126
cache .data .Store (key , value )
126
127
@@ -131,7 +132,9 @@ func (cache *Cache) Set(key *openapi.Config, value interface{}, duration time.Du
131
132
}
132
133
}
133
134
134
- // Get 如果用loadorstore还要生成client,这样的cache没有意义.
135
+ // Get 从缓存中获取给定配置键对应的 openapi 客户端。
136
+ // 如果缓存中存在该键,则直接返回对应的客户端实例;
137
+ // 如果缓存中不存在,则创建一个新的客户端实例,并加入缓存。
135
138
func (cache * Cache ) Get (key * openapi.Config ) (* openapi.Client , error ) {
136
139
value , ok := cache .data .Load (key )
137
140
if ok {
@@ -150,7 +153,6 @@ func (cache *Cache) Get(key *openapi.Config) (*openapi.Client, error) {
150
153
var GlobalCache = & Cache {}
151
154
152
155
func (apiDatasource * APIDatasource ) BuildClient (setting * APISource , param map [string ]interface {}, product string ) (* openapi.Client , error ) {
153
- // TODO:支持缓存的client, map, key是config
154
156
regex := regexp .MustCompile (`\[([^\]]+)\]` )
155
157
endpoint := setting .ProductConfigs [product ].Endpoint
156
158
flag := regex .MatchString (endpoint )
@@ -167,7 +169,6 @@ func (apiDatasource *APIDatasource) BuildClient(setting *APISource, param map[st
167
169
AccessKeyId : & setting .AccessKeyId ,
168
170
AccessKeySecret : & setting .AccessKeySecret ,
169
171
}
170
- log .DefaultLogger .Debug ("config finish without []" , "config" , config )
171
172
} else {
172
173
keys := []string {"RegionId" , "Region" }
173
174
region1 , exists := getValueIgnoreCase (param , keys )
@@ -183,10 +184,8 @@ func (apiDatasource *APIDatasource) BuildClient(setting *APISource, param map[st
183
184
AccessKeyId : & setting .AccessKeyId ,
184
185
AccessKeySecret : & setting .AccessKeySecret ,
185
186
}
186
- log .DefaultLogger .Debug ("config finish with []" , "config" , config )
187
187
}
188
188
client , err := GlobalCache .Get (config )
189
- // client, err := openapi.NewClient(config)
190
189
return client , err
191
190
}
192
191
@@ -202,8 +201,7 @@ func mapToQueryParams(data map[string]interface{}, prefix string, queries map[st
202
201
}
203
202
204
203
func processValue (value interface {}, prefix string , queries map [string ]string ) {
205
- log .DefaultLogger .Info ("processValue" , "value" , value , "prefix" , prefix , "queries" , queries )
206
- log .DefaultLogger .Info ("value type" , reflect .TypeOf (value ))
204
+ // log.DefaultLogger.Debug("processValue", "value", value, "prefix", prefix, "queries", queries)
207
205
rValue := reflect .ValueOf (value )
208
206
switch rValue .Kind () {
209
207
case reflect .Map :
@@ -248,7 +246,6 @@ func (apiDatasource *APIDatasource) QueryAPI(ch chan Result, query backend.DataQ
248
246
}()
249
247
250
248
// 前端的query解析为查询的参数
251
- log .DefaultLogger .Info ("unmarshal queryInfo" , query .JSON )
252
249
err := json .Unmarshal ([]byte (query .JSON ), & queryInfo )
253
250
if err != nil {
254
251
log .DefaultLogger .Error ("Unmarshal queryInfo" , "refId" , refId , "error" , err )
@@ -259,11 +256,10 @@ func (apiDatasource *APIDatasource) QueryAPI(ch chan Result, query backend.DataQ
259
256
}
260
257
return
261
258
}
262
- log .DefaultLogger .Info ("marshal queryInfo" , queryInfo )
263
259
264
260
if ! strings .HasSuffix (setting .ProductConfigs [queryInfo .Product ].Endpoint , "aliyuncs.com" ) {
265
261
err = errors .New ("endpoint is not end with aliyuncs.com, Illegal Endpoint" )
266
- log .DefaultLogger .Debug ("Endpoint is not end with aliyuncs.com, Illegal Endpoint" )
262
+ log .DefaultLogger .Info ("Endpoint is not end with aliyuncs.com, Illegal Endpoint" )
267
263
ch <- Result {
268
264
refId : refId ,
269
265
dataResponse : response ,
@@ -280,14 +276,8 @@ func (apiDatasource *APIDatasource) QueryAPI(ch chan Result, query backend.DataQ
280
276
//创建查询参数
281
277
params := CreateApiInfo (queryInfo , setting )
282
278
283
- log .DefaultLogger .Info ("Type of queryInfo.Params" , reflect .TypeOf (queryInfo .Params ))
284
-
285
- log .DefaultLogger .Info ("query Info Parmas" , queryInfo .Params )
286
279
queries := make (map [string ]string )
287
280
mapToQueryParams (queryInfo .Params , "" , queries )
288
- for key , value := range queries {
289
- log .DefaultLogger .Info ("key and value\n " , key , value )
290
- }
291
281
292
282
log .DefaultLogger .Info ("query params," , queries )
293
283
log .DefaultLogger .Info ("API params," , params )
0 commit comments