(c *gin.Context)
| 320 | } |
| 321 | |
| 322 | func TestChannel(c *gin.Context) { |
| 323 | channelId, err := strconv.Atoi(c.Param("id")) |
| 324 | if err != nil { |
| 325 | common.ApiError(c, err) |
| 326 | return |
| 327 | } |
| 328 | channel, err := model.CacheGetChannel(channelId) |
| 329 | if err != nil { |
| 330 | common.ApiError(c, err) |
| 331 | return |
| 332 | } |
| 333 | //defer func() { |
| 334 | // if channel.ChannelInfo.IsMultiKey { |
| 335 | // go func() { _ = channel.SaveChannelInfo() }() |
| 336 | // } |
| 337 | //}() |
| 338 | testModel := c.Query("model") |
| 339 | tik := time.Now() |
| 340 | result := testChannel(channel, testModel) |
| 341 | if result.localErr != nil { |
| 342 | c.JSON(http.StatusOK, gin.H{ |
| 343 | "success": false, |
| 344 | "message": result.localErr.Error(), |
| 345 | "time": 0.0, |
| 346 | }) |
| 347 | return |
| 348 | } |
| 349 | tok := time.Now() |
| 350 | milliseconds := tok.Sub(tik).Milliseconds() |
| 351 | go channel.UpdateResponseTime(milliseconds) |
| 352 | consumedTime := float64(milliseconds) / 1000.0 |
| 353 | if result.newAPIError != nil { |
| 354 | c.JSON(http.StatusOK, gin.H{ |
| 355 | "success": false, |
| 356 | "message": result.newAPIError.Error(), |
| 357 | "time": consumedTime, |
| 358 | }) |
| 359 | return |
| 360 | } |
| 361 | c.JSON(http.StatusOK, gin.H{ |
| 362 | "success": true, |
| 363 | "message": "", |
| 364 | "time": consumedTime, |
| 365 | }) |
| 366 | return |
| 367 | } |
| 368 | |
| 369 | var testAllChannelsLock sync.Mutex |
| 370 | var testAllChannelsRunning bool = false |
nothing calls this directly
no test coverage detected