@@ -121,6 +121,7 @@ type Cache struct {
121121 data sync.Map
122122}
123123
124+ // Set 将给定的键值对存储到缓存中,并根据指定的持续时间设置过期机制。
124125func (cache * Cache ) Set (key * openapi.Config , value interface {}, duration time.Duration ) {
125126 cache .data .Store (key , value )
126127
@@ -131,7 +132,9 @@ func (cache *Cache) Set(key *openapi.Config, value interface{}, duration time.Du
131132 }
132133}
133134
134- // Get 如果用loadorstore还要生成client,这样的cache没有意义.
135+ // Get 从缓存中获取给定配置键对应的 openapi 客户端。
136+ // 如果缓存中存在该键,则直接返回对应的客户端实例;
137+ // 如果缓存中不存在,则创建一个新的客户端实例,并加入缓存。
135138func (cache * Cache ) Get (key * openapi.Config ) (* openapi.Client , error ) {
136139 value , ok := cache .data .Load (key )
137140 if ok {
@@ -150,7 +153,6 @@ func (cache *Cache) Get(key *openapi.Config) (*openapi.Client, error) {
150153var GlobalCache = & Cache {}
151154
152155func (apiDatasource * APIDatasource ) BuildClient (setting * APISource , param map [string ]interface {}, product string ) (* openapi.Client , error ) {
153- // TODO:支持缓存的client, map, key是config
154156 regex := regexp .MustCompile (`\[([^\]]+)\]` )
155157 endpoint := setting .ProductConfigs [product ].Endpoint
156158 flag := regex .MatchString (endpoint )
@@ -167,7 +169,6 @@ func (apiDatasource *APIDatasource) BuildClient(setting *APISource, param map[st
167169 AccessKeyId : & setting .AccessKeyId ,
168170 AccessKeySecret : & setting .AccessKeySecret ,
169171 }
170- log .DefaultLogger .Debug ("config finish without []" , "config" , config )
171172 } else {
172173 keys := []string {"RegionId" , "Region" }
173174 region1 , exists := getValueIgnoreCase (param , keys )
@@ -183,10 +184,8 @@ func (apiDatasource *APIDatasource) BuildClient(setting *APISource, param map[st
183184 AccessKeyId : & setting .AccessKeyId ,
184185 AccessKeySecret : & setting .AccessKeySecret ,
185186 }
186- log .DefaultLogger .Debug ("config finish with []" , "config" , config )
187187 }
188188 client , err := GlobalCache .Get (config )
189- // client, err := openapi.NewClient(config)
190189 return client , err
191190}
192191
@@ -202,8 +201,7 @@ func mapToQueryParams(data map[string]interface{}, prefix string, queries map[st
202201}
203202
204203func 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)
207205 rValue := reflect .ValueOf (value )
208206 switch rValue .Kind () {
209207 case reflect .Map :
@@ -248,7 +246,6 @@ func (apiDatasource *APIDatasource) QueryAPI(ch chan Result, query backend.DataQ
248246 }()
249247
250248 // 前端的query解析为查询的参数
251- log .DefaultLogger .Info ("unmarshal queryInfo" , query .JSON )
252249 err := json .Unmarshal ([]byte (query .JSON ), & queryInfo )
253250 if err != nil {
254251 log .DefaultLogger .Error ("Unmarshal queryInfo" , "refId" , refId , "error" , err )
@@ -259,11 +256,10 @@ func (apiDatasource *APIDatasource) QueryAPI(ch chan Result, query backend.DataQ
259256 }
260257 return
261258 }
262- log .DefaultLogger .Info ("marshal queryInfo" , queryInfo )
263259
264260 if ! strings .HasSuffix (setting .ProductConfigs [queryInfo .Product ].Endpoint , "aliyuncs.com" ) {
265261 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" )
267263 ch <- Result {
268264 refId : refId ,
269265 dataResponse : response ,
@@ -280,14 +276,8 @@ func (apiDatasource *APIDatasource) QueryAPI(ch chan Result, query backend.DataQ
280276 //创建查询参数
281277 params := CreateApiInfo (queryInfo , setting )
282278
283- log .DefaultLogger .Info ("Type of queryInfo.Params" , reflect .TypeOf (queryInfo .Params ))
284-
285- log .DefaultLogger .Info ("query Info Parmas" , queryInfo .Params )
286279 queries := make (map [string ]string )
287280 mapToQueryParams (queryInfo .Params , "" , queries )
288- for key , value := range queries {
289- log .DefaultLogger .Info ("key and value\n " , key , value )
290- }
291281
292282 log .DefaultLogger .Info ("query params," , queries )
293283 log .DefaultLogger .Info ("API params," , params )
0 commit comments