http_global_client_init.go 635 B

123456789101112131415161718192021222324252627
  1. package http
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/glog"
  4. util_http_client "github.com/seaweedfs/seaweedfs/weed/util/http/client"
  5. )
  6. var (
  7. globalHttpClient *util_http_client.HTTPClient
  8. )
  9. func NewGlobalHttpClient(opt ...util_http_client.HttpClientOpt) (*util_http_client.HTTPClient, error) {
  10. return util_http_client.NewHttpClient(util_http_client.Client, opt...)
  11. }
  12. func GetGlobalHttpClient() *util_http_client.HTTPClient {
  13. return globalHttpClient
  14. }
  15. func InitGlobalHttpClient() {
  16. var err error
  17. globalHttpClient, err = NewGlobalHttpClient()
  18. if err != nil {
  19. glog.Fatalf("error init global http client: %v", err)
  20. }
  21. }