00 Preface Starting From 0 to Building an Enterprise Level Go Application

00 Preface Starting from 0 to Building an Enterprise-Level Go Application #

Hello, I’m Kong Lingfei, and I’m glad to chat with you about how to build an enterprise-level application using Go.

For the past 5 years, I’ve been using Go at Tencent to work on large-scale enterprise projects. For example, Tencent Cloud Functions (SCF), Tencent Game Container Platform (TenC), Tencent Game Microservice Middleware, and so on. Currently, I’m responsible for the development of Tencent Kubernetes Engine (TKE) at Tencent Cloud, focusing on infrastructure development in the field of cloud-native hybrid cloud.

“Cloud” is the trend, and Go is the language of the cloud era #

In recent years, I have noticed that many teams at Tencent have been transitioning to Go as their development language. It’s not just Tencent, major domestic companies like Alibaba, Huawei, and Baidu are also actively adopting Go. There are even teams that exclusively build projects with Go. With this trend comes an increasing demand for Go developers from these companies. So, why has Go become so popular? I believe there are two main reasons:

On one hand, Go is an excellent language with many core advantages, such as simplicity, built-in support for concurrent programming, cross-platform compilation, and automatic garbage collection. These advantages are the fundamental reasons why these teams choose Go.

On the other hand, Go is the language of the cloud era. Why do I say that? Let me explain further.

As cloud computing platforms mature, moving applications to the cloud has become an irreversible trend. Many companies are choosing to cloudify their infrastructure and business architecture. For example, Alibaba and Tencent are fully transitioning their internal businesses to the cloud. It can be said that full cloudification has become a key KPI at the company level. We can even understand that all future technologies will revolve around the cloud.

Currently, the cloud is evolving towards cloud-native architecture, and most influential projects in this architecture are built with Go. From the cloud-native technology stack language composition chart below, we can see that 63% of influential cloud-native projects are built with Go.

For a complete cloud-native technology stack, you can refer to the Cloud Native Landscape.

Therefore, in order to cloudify the infrastructure and business architecture, learning and modifying these cloud-native open-source projects is crucial. To save costs, it is best for a team to have a unified technology stack. Since we must learn Go and Go is so excellent, the best approach is to have the entire team’s language technology stack all in Go. This is another important reason why Go matters.

So, what do we use Go for? Of course, it is for project development. However, many developers face a series of challenges when using Go for project development.

What problems do you face when learning Go project development? #

I have worked with many developers who are new to the Go language. In order to learn Go project development, they search for a lot of Go-related technical articles online and spend a lot of time studying. However, when I do Code Review, I find that their code still has many issues.

For example, one developer wrote code that depends on a database connection, making it impossible to write unit tests. When I asked for more details, I found that the articles they referenced did not decouple the database layer from the business layer using interfaces.

Another example is that some developers create projects that are difficult to maintain, with a large number of Go packages with names like “common”, “util”, “const”. Just by looking at the package names, I have no idea what functionality the packages provide. After asking, I found out that they referenced a project with directories like “dao”, “model”, “controller”, “service”, which do not conform to Go’s design philosophy.

And these problems are just the tip of the iceberg. Overall, we face the following four main categories of problems when learning Go project development.

  1. Knowledge Gaps: Go project development involves many knowledge points that we are unaware of. When we try to learn, we find that many online articles have poor structure and inadequate explanations. To search for excellent articles, it takes a lot of time and effort.
  2. Limited ability to learn best practices: There are many articles online that introduce methods for building Go projects, but many of them are not best practices. After learning, our abilities and understanding do not improve optimally, and we have to spend time organizing our learning, resulting in less efficient progress.
  3. Not knowing how to develop a Go project completely: We learn a lot of Go development related knowledge points and building methods, but they are not systematic, comprehensive, or in-depth. After learning, we are still at a loss when it comes to integrating them into a cohesive Go project development system. We are still disorganized and inefficient when it comes to actual development.
  4. Lack of real-world projects to practice with, difficult to evaluate learning progress: To avoid working in isolation, we certainly want to learn from the development experience of major companies and their large-scale projects, and use them to evaluate our own learning achievements. However, it is difficult for us to come into contact with such projects in our daily lives, and we don’t have a way to study them.

To solve these problems, I have designed the “Go Language Project Development in Action” column, hoping to help you become an excellent Go developer and establish your own core competencies in the workplace.

How is this column designed? #

So how does the column “Go Language Project Development in Practice” solve the problems mentioned above? In this column, I will explain in detail the skills involved in the actual development process, based on a deployable and runnable enterprise application source code. This will help you thoroughly learn how to build enterprise-level Go applications and solve various issues encountered in Go project development.

On one hand, you will be able to have a high-level overview of the entire Go enterprise application development process, not only understanding the skills and development work required for an excellent enterprise application, but also knowing how to efficiently complete each stage of development. On the other hand, you will be able to delve into each skill point, mastering their specific construction methods, industry best practices, and firsthand development experience.

Lastly, I would like to emphasize that in addition to the above content, the column will ultimately deliver a set of excellent and executable enterprise application code. This code can meet the needs of most enterprise application development scenarios, allowing you to quickly build your own enterprise application based on it.

After all that has been said, what specific skills can we learn from this column? I have summarized them in the following diagram according to the development sequence, which includes most of the skill points in Go project development.

In addition to this, each skill point in the column is designed with “best practices” in mind. For example, the Go packages I use are the most widely adopted ones in the industry, and in their design, I also try to adhere to Go design patterns, Go development guidelines, Go best practices, go clean architecture, etc. At the same time, I will also try to integrate my own experience in frontline Go project development into the explanation, providing you with the most reliable advice. This experience and advice can help you avoid many detours in the process of application development.

In order to facilitate your learning of this course, I have divided the entire column into 6 modules. Among them, the first module is for preparing the practical environment, and modules 2 to 6 will guide you through the actual construction of an application according to the development process.

Practical Preparation: I will first guide you step by step in setting up a laboratory environment, and then help you deploy our practical project. While deepening your understanding of the practical project, I will also explain some deployment skills, including how to prepare development environment, create CA certificates, install and configure the databases and applications used, as well as shell script writing techniques.

Practical 1st Station: Standard Design: I will provide a detailed introduction to the 10 common development standards, such as directory standards, logging standards, error code standards, commit standards, etc. Through this module, you will learn how to design common standards, laying a solid foundation for efficiently developing a high-quality, readable, and maintainable Go application.

Practical 2nd Station: Basic Function Design or Development: I will teach you how to design or develop some basic functions in Go application development. These functions will affect the way the entire application is built, such as logging packages, error packages, error codes, etc.

Practical 3rd Station: Service Development: I will guide you through the code analysis of an enterprise-level Go project, allowing you to learn how to develop Go applications. During the analysis, I will also provide detailed explanations of various skill points in the Go development stage, such as how to design and develop API services, Go SDKs, client tools, etc.

Practical 4th Station: Service Testing: I will use the practical project as a basis to explain methods for unit testing, functional testing, performance analysis, and performance tuning. In the end, you will be able to deliver a thoroughly tested, production-ready service that is both performant and stable.

Practical 5th Station: Service Deployment: In this module, through the deployment of the practical project, I will show you how to deploy an enterprise application that is highly available, secure, has disaster recovery capabilities, and can easily scale horizontally. Here, I will focus on introducing two deployment methods: traditional deployment and containerized deployment. Each method has its own differences in deployment approach, complexity, and capabilities.

Finally, regarding how to study this column, I would like to give you some suggestions.

First, I recommend that you study the text and image content of this column first before diving into the source code. During the learning process, if you have any ideas, you can modify the code and verify the results. The code for this column is all hosted on GitHub, and you can click this link to view it.

Secondly, in this column, I will not provide a detailed explanation of every line of code. I will only select some core code to explain. If you have any questions about parts that were not covered, be sure to leave a message in the comments section, because in this column, I want to help you overcome all the difficulties encountered in the development process. Do not let small problems accumulate into big challenges, as it is truly not worth it. I can promise you that the response to comments may be delayed, but I will never be absent.

Alright, let’s start this challenging journey of Go project practice together from now on. Let’s work together to develop an excellent enterprise-level Go application and become a senior Go developer!