MCPcopy Index your code
hub / github.com/aiprodcoder/MIXAPI / TestChannel

Function TestChannel

controller/channel-test.go:322–367  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

320}
321
322func 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
369var testAllChannelsLock sync.Mutex
370var testAllChannelsRunning bool = false

Callers

nothing calls this directly

Calls 4

CacheGetChannelFunction · 0.92
testChannelFunction · 0.85
ErrorMethod · 0.80
UpdateResponseTimeMethod · 0.80

Tested by

no test coverage detected