http_client.go 521 B

1234567891011121314151617181920212223242526272829303132
  1. package service
  2. import (
  3. "net/http"
  4. "one-api/common"
  5. "time"
  6. )
  7. var httpClient *http.Client
  8. var impatientHTTPClient *http.Client
  9. func init() {
  10. if common.RelayTimeout == 0 {
  11. httpClient = &http.Client{}
  12. } else {
  13. httpClient = &http.Client{
  14. Timeout: time.Duration(common.RelayTimeout) * time.Second,
  15. }
  16. }
  17. impatientHTTPClient = &http.Client{
  18. Timeout: 5 * time.Second,
  19. }
  20. }
  21. func GetHttpClient() *http.Client {
  22. return httpClient
  23. }
  24. func GetImpatientHttpClient() *http.Client {
  25. return impatientHTTPClient
  26. }