Major release: v1.0 of the Momento Go client
Check out some highlights from our Go client SDK—and take it for a spin!
Today we’re excited to announce the 1.0 release of the Momento client for Go.
At Momento, simplicity is one of our north stars. We want the Momento experience to be simple and delightful for our users, on both the server side and the client side. On the server side, this means you just create your cache and go, and leave all of the scaling and operations concerns to us. On the client side, this means having an SDK that makes it simple and intuitive to write bug-free code that interacts with your cache, and not having to spend a ton of your time thinking about tuning, thread-safety, or other esoteric concerns.
To that end we’ve been hard at work over the last few weeks polishing up our Go client library, making sure the APIs are clean and easy to work with, and making sure it’s easy to consume from your Go environment. Now we’re ready to share the finished product with you!
Go client library highlights
One client
- momento.CacheClient is thread-safe and handles all of the network connection management for you, so you can just create a single instance and hit the ground running. You don’t need to worry about thread-safety or connection pools.
Discoverable response types for bug-free code
There are multiple types of responses you can get from an API call. For example, when you make a Get request to get a value from your cache, the response might be a *responses.GetHit or a *responses.GetMiss. Depending on which of those you get back, there will be a very different set of properties that you need to access on the response. (For example, a GetHit will have an r.ValueString() function exposed that contains the data from your cache, but a GetMiss will not.) The Momento Go client uses Type switches to give you a strongly-typed response object for each of those cases, so that you can easily discover all of the possible values in your IDE and get compile-time type checking to prevent bugs. It’s always more pleasant to find a bug at compile time than at run time!
Native Go Errors
We have continued to use the native Go error types with our Go SDK to take advantage of the Go ecosystem error package. Combined with our response types this gives you confidence that when an error is returned it is indeed an error. It also allows you as a developer to continue to write Go code in a familiar way by just checking if the last error value returned is nil. We also have several standard error types allowing you to handle each one in a controlled way if desired. For example handling a timeout error in a custom way would look like this:
if err != nil {
var momentoErr momento.MomentoError
if errors.As(err, &momentoErr) {
if momentoErr.Code() != momento.TimeoutError {
// handle timeout error in custom way
}
}
}
Integrate with your favorite Go logging framework
The Momento Go client provides a simple logging interface that you can use to integrate with the logging framework of your choice. The default logger uses the Go std lib log package, but you can pass in a MomentoLoggerFactory to configure the Momento client to route logs to the same destinations as the rest of your application. Our examples show how to integrate with Logrus, but you can easily adapt them to zerolog, zap, or any other logging framework.
Pre-built configurations
Tuning a network client can be a lot of work, and the best settings can differ pretty dramatically between environments. For example, the best settings to allow you to explore and debug from your laptop probably aren’t the same settings that you want in your low-latency production environment in the cloud. To help keep things simple, the Momento Go client comes with several pre-built configurations designed for different types of environments like these. The configuration is fully customizable if you have a unique need that we haven’t accounted for, but we did our best to make sure we would have the 90% case covered so that you don’t need to spend your engineering hours on tuning.
Take the Go client for a spin today
You can get started with the 1.0 version of the Momento Cache Go client right now. If you haven’t created a free Momento cache yet, visit our Momento getting started docs. Then check out the docs for getting started with the Go client on GitHub!