http_client.go 585 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package dify_invocation
  2. import (
  3. "net"
  4. "net/http"
  5. "net/url"
  6. "time"
  7. )
  8. var (
  9. PLUGIN_INNER_API_KEY string
  10. baseurl *url.URL
  11. client *http.Client
  12. )
  13. func InitDifyInvocationDaemon(base string, calling_key string) error {
  14. var err error
  15. baseurl, err = url.Parse(base)
  16. if err != nil {
  17. return err
  18. }
  19. client = &http.Client{
  20. Transport: &http.Transport{
  21. Dial: (&net.Dialer{
  22. Timeout: 5 * time.Second,
  23. KeepAlive: 120 * time.Second,
  24. }).Dial,
  25. IdleConnTimeout: 120 * time.Second,
  26. },
  27. }
  28. PLUGIN_INNER_API_KEY = calling_key
  29. return nil
  30. }