From 679a42b1c548ee53db6e23ad978b3ee04014a68c Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Wed, 11 Sep 2024 21:55:54 +0100 Subject: [PATCH] Use a pointer for BaseClient.productCheckMu I would like to convert a TypedClient to a regular Client; my main use-case for this is so I can use it for the bulk indexer. Converting a TypedClient to Client is fairly straight-forward: func ToClient(tc *elasticsearch.TypedClient) *elasticsearch.Client { c := &elasticsearch.Client{ BaseClient: tc.BaseClient, } c.API = esapi.New(c) return c } Which works, but also gives an error on go vet; literal copies lock value from ns.TypedClient.BaseClient: github.com/elastic/go-elasticsearch/v8.BaseClient contains sync.RWMutex This fixes that. --- elasticsearch.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/elasticsearch.go b/elasticsearch.go index c736ded991..52d7aaa3be 100644 --- a/elasticsearch.go +++ b/elasticsearch.go @@ -138,7 +138,7 @@ type BaseClient struct { compatibilityHeader bool disableMetaHeader bool - productCheckMu sync.RWMutex + productCheckMu *sync.RWMutex productCheckSuccess bool } @@ -190,6 +190,7 @@ func NewClient(cfg Config) (*Client, error) { disableMetaHeader: cfg.DisableMetaHeader, metaHeader: initMetaHeader(tp), compatibilityHeader: cfg.EnableCompatibilityMode || compatibilityHeader, + productCheckMu: new(sync.RWMutex), }, } client.API = esapi.New(client) @@ -223,6 +224,7 @@ func NewTypedClient(cfg Config) (*TypedClient, error) { disableMetaHeader: cfg.DisableMetaHeader, metaHeader: metaHeader, compatibilityHeader: cfg.EnableCompatibilityMode || compatibilityHeader, + productCheckMu: new(sync.RWMutex), }, } client.API = typedapi.New(client)