Skip to content

Commit

Permalink
Use a pointer for BaseClient.productCheckMu
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arp242 committed Sep 11, 2024
1 parent 98a819b commit 0790f2d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ type BaseClient struct {
compatibilityHeader bool

disableMetaHeader bool
productCheckMu sync.RWMutex
productCheckMu *sync.RWMutex
productCheckSuccess bool
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0790f2d

Please sign in to comment.