Posts with tag: golang
Have you ever noticed your web application working a bit slower than you expected? Or maybe it looks OK, but some client complains that it's slow for them? If you don't monitor your app, it's virtually impossible to verify if this is true. That's why you should use Prometheus to find out.
If you've been around the IT industry for more than a few moments, you probably already know that "it works on my machine" is no longer a valid excuse for your product misbehavior. In order to achieve the highest level of quality, we as a community of professionals have embraced an idea of Continuous Integration, and for all of you that think it's too much effort to set it up, I introduce CircleCI.
We've already seen how you can implement a simple queue in Redis using a list key and smart pushing and popping the elements. But is there any better, cleaner and more suitable way to do such a thing? Does Redis provide any other possible approach? You bet! Enter Pub/Sub.
As you probably already know, Redis goes well beyond getting and setting values. One of the less often used features in the database is the ability to implement a pretty simple task queue and share it between a producer and a consumer. Let's take a look how you can do that in a few steps.
Having implemented counting in Redis using one counter per value seems the way to go, as long as we know about all the things we want to keep track of. Once we want to monitor some more dynamic structures, this quickly becomes an issue. There is, however, a way to do this smart. We need to know what are hashes.
Since its initial release in 2009, Redis has become one of the most popular NoSQL solutions and almost a synonym for a key-value database. Thanks to being around for some time, there are a few use cases that it is more than suitable for. One of them is a persistent store for users' sessions in a web application. While it has already been implemented and available using various open source libraries, let's see if we can do it by ourselves.
Building a gRPC service is not that complicated, even if we want to add some security, custom interceptors and complex request or response messages. Unfortunately, it's still not as popular as we'd like, and most of the time we need to support HTTP as well. Building two identical APIs seems like a terrible idea, right? With gRPC Gateway you can save lots of time, so let's jump in.
Setting up communication between the server and its clients via gRPC is really simple, but what about the security? It's not that hard, either. Let's take a look.
In the previous post, we started looking on gRPC by generating code using protocol buffers. As important as that step was, it would not be quite that powerful without some actual use case, where we'd like to have the same structure created on both sides od communication. This blog post provides you with such example use case - let's see how you can build your first gRPC server and its client in Golang.
When building a microservice architecture, two of the most common approaches are a common messaging queue and HTTP APIs that are exposed and consumed by each element of the project. Despite those approaches being perceived as well-known and battle-tested, the community warmly welcomed another player to the game - gRPC. This is an introduction to this way of communication, and the story has, to begin with, a date with Protocol Buffers - something that sets gRPC apart.
So far we've seen how to build a GraphQL API that serves the user with data stored in the databases. But what about making changes? With a few tweaks in the structure, we can achieve this as well. Let's take a look on things called mutations.
Building an API in GraphQL looks very easy, as you could have already seen based on two previous posts. The thing is that everything looks simple when no parameters are provided, right? Let's take a look at how to make our API just a bit more dynamic.
In the previous post, we've seen how easy it is to set up a simple GraphQL server in Golang. The problem is, that we have hardly done anything special, that would distinguish our API from one written for REST. It's time for something more advanced, that is nested objects and fetching them from different sources.
For a long time building an API (eg. for web applications) has become associated with REST. Meanwhile, less than two years ago, Facebook announced a technology they've been using for some time called GraphQL. It's an alternative way to provide data to the users, where each client can squeeze multiple queries into a single one.
Any web application that is targeted to more than one user is likely required to have some kind of authorization technique so that it can determine if given user can execute certain actions. The problem how to do this remains, despite dozens of years passed in software development world. One of the approaches, gaining much popularity recently are JSON Web Tokens. This short post shows how you can use them in your Golang application.
In software development, everything seems to be easy until something goes terribly wrong. It might be a major crash of the database server, unexpected interaction with 3rd party service, or our main application getting really slow. How can we monitor and measure the last issue? Take a look at the ways to profile Go application.
When it's good, it's good. But what if something goes wrong in your Go application? For on apparent reason it just doesn't behave the way you wanted. You could add some console messages here and there, but is there really the only possible way to go? You absolutely need to know how to debug your code, because one day you will really need it.
Getting started with Kubernetes might seem to be slightly more complicated than with some other awesome tools you've heard about. It's because to see it in action you need to have an access to some hosting provider that allows you to deploy your containerized applications and expose them to the world. Fortunately, there is a way to play around with K8s locally - using Minikube.
If you want to deploy your application to the cloud, you may be considering to put it into a Docker container, so that you make sure the environment will be identical both in the cloud and locally. Great thing is, dockerizing your Go application won't take more that five minutes!
Writing tests first, before implementation is easy when our functions don't rely on any external tools or systems. What about unit testing the code that is responsible for interactions with the database? This requires some additional effort, but it pays off big time later on.
With Go gaining more and more popularity, it is becoming more common to create a web application with it. This, however, can be a bit problematic when it comes to writing unit tests. Fortunately, in Golang it's easier than you may think.
Handling errors in Golang seems to be a pretty easy thing to do. As a convention, whenever a function can result in some incorrect way, some error is returned as one of its values, which then can be passed further or displayed to the user. But how exactly should you do it? And is the standard package enough for all this? According to Dave Cheney, it's not.
Long gone are times when all the communication between web application server and its clients was limited to request-response communication. Nowadays, especially in systems where it is important to notify users about various events, it's absolutely necessary to use websockets in order to push information from the central point. Let's take a look on how to create simple WS server using Golang.
One of the most common rules of Golang development is that you should write code yourself as long as you can while choosing an external dependency as a last resort. This approach is completely different that that of Node JS, which is most popular for creating HTTP servers and applications. How does it look for creating web apps with Golang? Let's take a look at Iris framework, which can really speed up your development.
It is very difficult, not to say impossible, to build an application, a library of a tool without using any external dependencies. Even in Golang, where it is always preferred to do something yourself than use an 3rd party library, you need to use eg. database drivers and there is just no sense to reinvent the wheel. How should you manage your dependencies, so that any changes made by their authors don't break your work?
Isn't Go just a perfect language for microservices? Peter Bourgon certainly thought so when he started a project that was supposed to make it popular for this stuff as well. After a few months it grew into a pretty cool and interesting tool for Go developers. Let's see what you need to do to use it and how it can make your work easier.
Every now and the you face some kind of a problem in your application and come up with two (or more) solutions. You then wonder which is more efficient, which way should you go? If your problem happens to occur in a Golang application, Benchmarks come to rescue! Take a look on how you can measure performance of your code.
In the previous post we saw how to make queries to MySQL database using a small Go application. But your app will rarely be limited to read-only mode, so we obviously need to know how to save stuff to the database as well. Don't worry, it's even easier than selects!
Nowadays every application has to deal with data, which means your application has to be able to persist and read some information. You can do this using various data sources, such as files, SQL databases or NoSQL. This post deals with a thing I needed to do recently, that is fetching data from MySQL database using Go language.