(ctx context.Context, client *http.Client)
| 453 | } |
| 454 | |
| 455 | func runChecks(ctx context.Context, client *http.Client) []serviceCheckResult { |
| 456 | results := make([]serviceCheckResult, len(streamServices)) |
| 457 | var wg sync.WaitGroup |
| 458 | |
| 459 | for i, svc := range streamServices { |
| 460 | wg.Add(1) |
| 461 | go func(idx int, s streamServiceDef) { |
| 462 | defer wg.Done() |
| 463 | result := serviceCheckResult{Service: s.name} |
| 464 | |
| 465 | if s.customCheck != nil { |
| 466 | result.Unlocked, result.Region, result.Note = s.customCheck(ctx, client) |
| 467 | results[idx] = result |
| 468 | return |
| 469 | } |
| 470 | |
| 471 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, s.url, nil) |
| 472 | if err != nil { |
| 473 | result.Note = "请求构建失败" |
| 474 | results[idx] = result |
| 475 | return |
| 476 | } |
| 477 | req.Header.Set("User-Agent", checkUserAgent) |
| 478 | req.Header.Set("Accept-Language", "en-US,en;q=0.9") |
| 479 | req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") |
| 480 | |
| 481 | resp, err := client.Do(req) |
| 482 | if err != nil { |
| 483 | result.Note = "连接超时" |
| 484 | results[idx] = result |
| 485 | return |
| 486 | } |
| 487 | defer resp.Body.Close() |
| 488 | |
| 489 | body, _ := io.ReadAll(io.LimitReader(resp.Body, 65536)) |
| 490 | result.Unlocked, result.Region, result.Note = s.checkFn( |
| 491 | resp.StatusCode, resp.Request.URL.String(), string(body), |
| 492 | ) |
| 493 | results[idx] = result |
| 494 | }(i, svc) |
| 495 | } |
| 496 | |
| 497 | wg.Wait() |
| 498 | return results |
| 499 | } |
| 500 | |
| 501 | // checkSpotify 参考 HsukqiLee/MediaUnlockTest checks/Spotify.go: |
| 502 | // 通过 signup API 触发账号创建预检,返回 status/Country/is_country_launched 判定。 |
no test coverage detected