SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
util/http: lazily init the global HTTP client to fix admin metrics nil panic (#10044)
Chris Lu16ba8af0b77f
diff --git a/weed/util/http/http_global_client_init.go b/weed/util/http/http_global_client_init.goindex 0dcb05cfd3..43fecf1d40 100644--- a/weed/util/http/http_global_client_init.go+++ b/weed/util/http/http_global_client_init.go@@ -1,27 +1,37 @@package httpimport (+ "sync"+"github.com/seaweedfs/seaweedfs/weed/glog"util_http_client "github.com/seaweedfs/seaweedfs/weed/util/http/client")var (- globalHttpClient *util_http_client.HTTPClient+ globalHttpClient *util_http_client.HTTPClient+ globalHttpClientOnce sync.Once)func NewGlobalHttpClient(opt ...util_http_client.HttpClientOpt) (*util_http_client.HTTPClient, error) {return util_http_client.NewHttpClient(util_http_client.Client, opt...)}+// GetGlobalHttpClient returns the process-wide HTTP client, initializing it on+// first use. Lazy init keeps callers that bypass weed.go's main (in-process+// test harnesses, libraries) from dereferencing a nil client.func GetGlobalHttpClient() *util_http_client.HTTPClient {+ globalHttpClientOnce.Do(initGlobalHttpClient)return globalHttpClient}func InitGlobalHttpClient() {- var err error+ globalHttpClientOnce.Do(initGlobalHttpClient)+}- globalHttpClient, err = NewGlobalHttpClient()+func initGlobalHttpClient() {+ client, err := NewGlobalHttpClient()if err != nil {glog.Fatalf("error init global http client: %v", err)}+ globalHttpClient = client}