Go API Client v3 is released

release
go
api-clients
#1

Hi everyone!

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 :rocket:

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.

:hammer_and_pick: 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 Map or 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:

:thinking: 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.

:stopwatch: 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:

three

Multiple operations can be also made blocking thanks to the new wait.Group structure:

four

:fire: 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.

five

:toolbox: 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.

:vulcan_salute: 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.

:bug: More granular debugging

Thanks to the new debug.Enable() and debug.Disable() functions, specific Algolia code snippets can now be guarded to display raw request and response payloads on the standard output.

six

:syringe: Injectable requester

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.

:robot: Indexing methods can take an iterator and automatically create batches

The SaveObjects indexing method now accepts iterators (i.e. instances which implement our Iterator interface).

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.

:eyes: Equality functions

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.

:floppy_disk: 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.

:checkered_flag: 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!

:raised_hands: 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.

3 Likes