After the recent releases of our new PHP, C#, Python and Java API clients, we are really excited to come back to you with an expected but nonetheless exciting news.
Today, we are proud to announce the release of the v3.0.0 of our new Go API client
As for other recent releases, we now respect the new standard implementation of our API clients and integration tests are following our new common test suite. However, the major change comes at the DX level with a lot of new features to ease and shorten Go implementations.
Use of user-defined structures for objects instead of ad hoc ones
Because generics are not available in Go, there is no convenient way to represent user-defined i.e. arbitrary objects like records in our library. Because of this, users had to define their records in term of
Object which were ad hoc structures. The drawback was that all user-defined needed to be converted into those types when sending records to the API, and the other way around for objects coming from the search API. Now, user-defined objects can be directly indexed:
Functional options as optional parameters
To counter the lack of function overloading in Go, we now let most functions accept optional parameters and have implemented all those possible Algolia options with dedicated structures, which better enforce type-safety of the overall client.
An easy way to wait for any operation to be complete
By making all asynchronous Algolia responses implement a new
Wait interface, most of the operations can be made blocking until completion by calling
Wait(). And it also works on API key related methods! For instance, instead of explicitly call
waitTask or pooling on changes, you can now write:
Multiple operations can be also made blocking thanks to the new
Bring the DX one step further
We added new high-level helpers that are not just simple mapping to API endpoints. It is now possible to both replace and copy part or all of indices of the same application but also to copy indices across applications.
Easier index settings
The type used for index settings was different whether it was retrieved from the API via
GetSettings (which was a
Settings structure) or sent via
SetSettings (which was a
Map structure). Helpers were provided to ease conversions but they were not exempt of bugs.
Index settings are now uniquely represented by the new
Settings structure which is used everywhere is the same way.
Specialized client instances
Our API Clients aren’t only handling search methods but also analytics and insights. We separated them into dedicated clients to make clear what to use and when.
More granular debugging
Thanks to the new
debug.Disable() functions, specific Algolia code snippets can now be guarded to display raw request and response payloads on the standard output.
Our library is using the HTTP client from the Go standard library. However, if you do not want to use it, you can inject your own requester into our library. Good news is, even if you inject another requester it will run under our retry strategy.
Indexing methods can take an iterator and automatically create batches
SaveObjects indexing method now accepts iterators (i.e. instances which implement our
Also, by automatically creating batches, we ensure we optimize the number of network calls for our users without having them to think about it. For very specific use-cases, the batch size can be changed using the
MaxBatchSize configuration field.
Some Algolia structures such as synonyms, rules and settings are now easier to manipulate but can be difficult to compare, especially when default values can be absent. This is why most of those structures now offer
Equal() functions and methods to compare instances, whether default values are set or not.
No more confusion between Add and Save
We dropped the verb
Add. Now, all
Save methods mean either you add something new or replace it completely if it was already existing. For
SaveObjects, you can control this behavior explicitly with the
opt.AutoGenerateObjectIDIfNotExist(true|false) optional parameter.
Where should I start?
We no have a repository with playgrounds for most of our clients.
The Go playground comes with several examples - notably, how to add the client as a dependency using Go modules and a basic indexing/searching snippet. Check it out!
You’d like to contribute?
You’d like to contribute? Before start, we want to let you know that your feedback is important to us! Please consider start using this
v3 today! Found a bug or see something that can be improved? Report it here: Github issues or Pull Requests.