Go has a great feature that it can be packaged into a single binary which is easy for distribution. However when it comes to web application it’s a bit tricky becuase 1. you need to bind frontend assets into the binary and 2. you need to deal with the routing if you are building a single page application(SPA).
In this post I will walk you through how to embed a vite built react app into a go binary and how to handle the routing using gin framework.
Login through third parties including Google, Github etc has been an essential requirement for most web applications. The underlying of this process is oauth authentication. The following diagram from Google shows the process of oauth authentication.
As you can see, it is a bi-directional communication between the app and the oauth server. The app needs to handle the callback. This is usually done by a backend server. However, you don’t have to have a dedicated backend server for this if what you want is just to get the user’s information from the third party.
Infinite scrolling is a feature that allows you to load content continuously when users scroll down the page. It is widely used in social media apps such as Facebook, Twitter, Instagram, etc. I happened to implement this feature with react recently and I would like to share my experience and thoughts on this topic.
I was looking for an all-in-one solution for building apps with golang. Then I found Wails, it is claimed as a cross-platform framework for building apps with Go as backend. On the frontendside, it allows you to use modern web technologies such as Vue.js, React.js, and Angular.js. It sounds fancinating, so I decided to give it a try and dig a little bit on how it works.
This is the start a series of posts about the notes I made when I read the source code of popular open source projects. I myself learned a lot from digging into the code of open source projects. I hope it can help you too.
I will start with Loki, a log aggregation system inspired by Prometheus.
Overview grafana/loki consists two components:
Loki: the log aggregation system Promtail: the agent to collect logs and send to Loki in a nutshell, loki and promtail is a service-client arhitecture.
When you deploy springboot apps to production, you would like to know how your apps are doing. You would like to know how many requests are coming in, how much memory is used, how many errors are there, etc. In this article I would like to share my experience on how to monitor your springboot app with prometheus and grafana.
Structure Assuming you already know what is prometheus and grafana. If not, you can check out their official websites.
Go is a fancinating language for building backend service, while React is a modern framework for building frontend web app. I would like to share my experience on how you can put this two together to build a full stack web app.
The structure The chance is you probably can find a template on github and develop your app based on that. But I recommend you pause for a second and think about the structure of the codebase.
Grafana has developed really fast in the past few years. It has been the de facto standard for observability. I have been using grafana and loki for a while and I am really impressed by its performance and the quality of the code. Grafana builds most its backend components in Go. Meanwhile I am also using Go to build stuff. So it seems a good idea to learn some good practice from Grafana’s codebase.
The framework I am using to build this blog is Hugo. Under the hood, it uses Cobra to build the command line interface. Besides Hugo, Cobra is also used by many other popular projects such as kubectl, github cli, etc. I was curious about how it works so I decided to learn by building a simple command line app with it.
The app I am going to build is a regex tool that uses openAI’s API to generate a regex expression based on a list of strings or the semantic meaning of the given strings(e.
Goroutine is perhaps the main reason why people choose golang for their projects. It is a lightweight thread managed by the go runtime. It is also easy to use. You can simply use go keyword to start a goroutine. However, if you need to run a large number or cpu intensive goroutines, you might want to use a goroutine pool to manage them and make sure you don’t run out of memory or cpu resources.