diff --git a/content/articles/top-5-golang-framework/beego-image.png b/content/articles/top-5-golang-framework/beego-image.png new file mode 100644 index 00000000000..dbac8c93330 Binary files /dev/null and b/content/articles/top-5-golang-framework/beego-image.png differ diff --git a/content/articles/top-5-golang-framework/echo-image.png b/content/articles/top-5-golang-framework/echo-image.png new file mode 100644 index 00000000000..a42b4d177ac Binary files /dev/null and b/content/articles/top-5-golang-framework/echo-image.png differ diff --git a/content/articles/top-5-golang-framework/fasthttp-image.jpg b/content/articles/top-5-golang-framework/fasthttp-image.jpg new file mode 100644 index 00000000000..747c82837af Binary files /dev/null and b/content/articles/top-5-golang-framework/fasthttp-image.jpg differ diff --git a/content/articles/top-5-golang-framework/fiber-image.png b/content/articles/top-5-golang-framework/fiber-image.png new file mode 100644 index 00000000000..ca91a35f5fa Binary files /dev/null and b/content/articles/top-5-golang-framework/fiber-image.png differ diff --git a/content/articles/top-5-golang-framework/gin-image.jpg b/content/articles/top-5-golang-framework/gin-image.jpg new file mode 100644 index 00000000000..42e8cbc3eef Binary files /dev/null and b/content/articles/top-5-golang-framework/gin-image.jpg differ diff --git a/content/articles/top-5-golang-framework/gokit-image.png b/content/articles/top-5-golang-framework/gokit-image.png new file mode 100644 index 00000000000..c325987733b Binary files /dev/null and b/content/articles/top-5-golang-framework/gokit-image.png differ diff --git a/content/articles/top-5-golang-framework/golang-image.jpg b/content/articles/top-5-golang-framework/golang-image.jpg new file mode 100644 index 00000000000..81d3f787731 Binary files /dev/null and b/content/articles/top-5-golang-framework/golang-image.jpg differ diff --git a/content/articles/top-5-golang-framework/hero-image.jpg b/content/articles/top-5-golang-framework/hero-image.jpg new file mode 100644 index 00000000000..7de776da959 Binary files /dev/null and b/content/articles/top-5-golang-framework/hero-image.jpg differ diff --git a/content/articles/top-5-golang-framework/index.md b/content/articles/top-5-golang-framework/index.md new file mode 100644 index 00000000000..8f3fd94f93e --- /dev/null +++ b/content/articles/top-5-golang-framework/index.md @@ -0,0 +1,284 @@ +# Top 5 Golang Frameworks (2022) + +![hero image](/top-5-golang-framework/hero-image.jpg) + +### Table of Content + +[Introduction](#Introduction) + +[What is Golang](#What-is-Golang) + +[Importance of using a Golang framework](#Importance-of-using-a-Golang-framework) + +[The Top 5 Golang Framework](#The-Top-5-Golang-Framework) + +[Conclusion](#Conclusion) + +### Introduction + +Golang since its first public release in 2009 has gained massive popularity in the web development community as the go-to choice of programming language for writing APIs and developing web services among developers. + +Moreover, just as we have drawbacks in other programming languages, we also have in GO.  + Some examples of such drawbacks include: + +- Lack of Generics. +- Dependency Management +- Error Handling + \* Unfortunately, the main challenge faced with writing vanilla Golang is that to get functions to work efficiently, the net/http library requires plenty of outside work and boilerplate code making it inflexible. + +But thanks to the different Golang frameworks that have also emerged to solve this challenge, and to many more that are steadily rising. + +While there are now different frameworks available for use, there's another challenge, which is choosing the best framework to use among these different frameworks when building a Golang application. + +This can pose as a really difficult task which is where this article comes in, to give a comprehensive list of the top 5 Golang frameworks to serve as a guide for Golang developers when choosing which framework to use for their Golang project. + +From this list the developer would get to know the different features of the different Golang frameworks, to give them an insight into what they can achieve with each framework. + +### What is Golang? + +![golang image](/top-5-golang-framework/golang-image.jpg) + +Goland is an open-source, statically typed programming language that is becoming more popular in the web development community due to its built-in net/http library and how simple it is to create a Go HTTP server. + +Golang is used to build simple, systematic, and secure software. + +The Golang language was modeled after the C language and some inspiration from the productivity and relative simplicity of Python +Golang combines the best features of this programming language like: + +- Easy Usage +- High-level efficiency and static typing +- Advanced Productivity +- Advanced performance for networking and full utilization of multi-core power C and C++ + +It comes with tools that easily perform the following task: + +- Manage objects +- Provide static typing along with concurrency +- Memory safety +- Garbage collection + +It was designed at Google by [Robert Griesemer](https://en.wikipedia.org/wiki/Robert_Griesemer_%28computer_programmer%29), [Rob Pike](https://en.wikipedia.org/wiki/Rob_Pike), and [Ken Thompson](https://en.wikipedia.org/wiki/Ken_Thompson) its official name is "Go" but it's popularly known as Golang because of its former domain name, golang.org. + +You can check [Wikipedia ](https://en.wikipedia.org/wiki/Go_%28programming_language%29)for more info +Alright, now that we have an overview of what Golang is and its basic feature. Let's delve right into the Top 5 Golang frameworks that you choose from in 2022. + +### Importance of using a Framework for your Golang application? + +There is no doubt we can build a small application without necessarily using a framework but if we are looking at building production-level applications then using a framework is important. + +Using a framework helps the developer to directly write the APIs, save time, and carry out debugging easily. + +One major benefit of using a framework is that it comes with additional features and services which developers can leverage if there is a need to add similar features to their software rather than writing full software themselves. + +Now that we have seen the importance of using a framework for our Golang application, lets delve into the top 5 Golang frameworks + +### The Top 5 Golang Framework + +Below are going the top 5 Golang frameworks that we are going to explore based on my personal experience with the language and based on specific criteria such as popularity according to Github stars. + +| Project Name | Stars | Forks | +| ----------------------------------------------- | :---: | ----: | +| [gin](https://github.com/gin-gonic/gin) | 62.1k | 6.8k | +| [beego](https://github.com/beego/beego) | 28.7k | 5.5k | +| [kit](https://github.com/go-kit/kit) | 23.7k | 2.3k | +| [echo](https://github.com/labstack/echo) | 23.5K | 2k | +| [fasthttp](https://github.com/valyala/fasthttp) | 18.3k | 1.5k | + +You can check the full list here on [Github](https://github.com/mingrammer/go-web-framework-stars) stars + +Based on the popularity according to the GitHub star, we have the following list of the best Golang frameworks. + +1. [gin](https://github.com/gin-gonic/gin) +2. [beego](https://github.com/beego/beego) +3. [kit](https://github.com/go-kit/kit) +4. [echo](https://github.com/labstack/echo) +5. [fasthttp](https://github.com/valyala/fasthttp) + +### gin + +![gin image](/top-5-golang-framework/gin-image.jpg) + +gin ranks first on our list with 62.1K stars and 6.8k forks on GitHub making it the most popular framework amongst the top 5 Golang frameworks. +gin is a high-performance HTTP web framework basically used for building web applications, microservices, and RESTful APIs in(Go). + +gin comes with functionalities like routing, rendering, middleware support, etc. which helps to reduce the usage of boilerplate code in our Golang application + +Gin's middleware support allows developers to write middleware that can be plugged into one or more request handlers which makes it simple to build a request handling pipeline. + +One of the great features of gin is its Martini-like API which has better performance up to 40 times faster than Martini. +Furthermore, it comes with the following key features: + +#### Features of gin + +- **Good documentation:** gin comes with pretty good documentation to get anyone started with the framework, and they are broad and comprehensive. Covers most of the tasks that a developer will need to do relating to the router in the docs and on GitHub. + +- **Simplicity:** gin is a minimalistic framework, it is so simple that it only includes the most essential features and libraries needed with little to no boilerplate to bootstrap applications. This simple nature of Gin makes it a great fit for developing high-performance REST APIs. + +- **Error handling:** Errors encountered during an HTTP request are documented as they occur, using the middleware the errors are written to a log file, to a database, and sent through the network. + +- **Extensible:** The gin has some of the well-tested middleware that makes developing with Gin interesting. These features include compression with GZIP, authentication with an authorization middleware, and logging with external solutions such as Sentry. + +- **Performance:** gin is known to run 40 times faster when compared to Martini and other Golang frameworks. + +- **JSON validation:** This feature helps developers get accurate values by validating and checking the existence of the required values when a JSON request is sent. + +**Biggest drawback:** gin is suitable for building small applications but not suitable for developing large server applications or complex enterprise-level server functions. + +### beego Framework + +![beego image](/top-5-golang-framework/beego-image.png) + +beego ranks second on the list of top 5 Golang frameworks with 28.7k stars and 5.5k forks on Github.  +It is an open-source, high-performance web framework used for developing enterprise applications and for the quick launching of API. + +It is simple and powerful and offers automated testing and code hot compiling, and can be used for developing RESTful applications web apps, and backend services. + +beego is similar to the Django framework in Python. It offers a ton of features like the typical Model-View-Controller (MVC) which is helpful if you're coming from Python. + +beego has a built-in command-line tool known as the Bee Tool that watches and helps find code changes and runs tasks when changes are detected. +beego also integrates an Object-Relationship Map (ORM), logging systems, an HTML template engine, and many other libraries. +It is inspired by Tornado, Sinatra, and Flask. + +#### beego is composed of four parts: + +1. **Base modules:** you will find the log module, config module, and governor module here; + +2. **Task:** for running timed tasks or periodic tasks; + +3. **Client:** including ORM module, httplib module, cache module; +4. **Server:** including web module. + +#### Features of beego + +- **Easy to use:** It is easy to use Beego tools to build web apps quickly with features including code hot compile, automated testing, and automated packing and deploying thanks to its RESTful support, and MVC model. + +- **Intelligent:** beego comes with intelligent routing and monitoring which provides us with full control to monitor QPRS, memory and CPU usage, and goroutine status. + +- **Modular:** beego comes with powerful built-in modules including session control, caching, logging, configuration parsing, performance supervising, context handling, ORM supporting, and requests simulating. + +- **High Performance:** With native Go HTTP package to handle the requests and the efficient concurrence of a goroutine. Your Beego applications can handle massive traffic. + +**Biggest drawback:** beego is not a great tool in the hands of a beginner since it's not easy to master due to its possibilities and scope. it is a tool for an experienced developer. + +### Go Kit  + +![Go kit image](/top-5-golang-framework/gokit-image.png) + +Go kit is not a framework but a library and it is a lightly opinionated toolkit designed for building microservices and also suited for building elegant monoliths in Go. + +Ranking third with 23.7k stars and 2.3k forks on gitHub. It comprises packages and guidelines that provide a comprehensive, and robust way to build microservices for organizations of any size. + +With Go Kit, we can implement components such as + +- Logging +- Metrics +- Tracing +- Circuit breaking +- rate limiting + +Implementing this component is made possible due to the Go kit libraries that are provided for us. These components are essential requirements for running microservices in production. + +There are three major components in the Go kit-based application architecture: + +- Transport layer +- Endpoint layer +- Service layer + +**Transport layer:** Services in any microservices-based distributed systems often communicate to each other using concrete transports like HTTP or gRPC, or using pub/sub systems like NATS.This is possible in go kit due to its support for various transport for serving services. + +**Endpoint layer:** Endpoints are the building block of any web app that involves servers and clients. Go kit provides a method to convert service to an endpoint to make RPC-style communication between servers and clients. + +**Services:** The Go kit services are modeled as interfaces. Each service method converts as an endpoint by using an adapter and is exposed by using concrete transports. Because of the clean architecture, a single Go kit service can be exposed by using multiple means of transport + +#### Features Of Go kit + +- Operates in a heterogeneous SOA(service-oriented architectures) +- Provides security for RPC( remote procedure call) which is Its primary messaging pattern. +- Pluggable serialization and transport - not just JSON over HTTP. +- Operate within existing infrastructures - no mandates for specific tools or technologies. + +**Biggest drawback:** The overhead of adding an API to service is very high due to the heavy use of interfaces. + +### echo Framework + +![echo image](/top-5-golang-framework/echo-image.png) + +When it comes to high-performance, echo is one of the Golang frameworks with high performance, with 23.5K star and 2k fork on gitHub it ranks as fourth on our list. +It is an extensible and minimalist web framework with a well-optimized zero-heap HTTP router, which causes routes in echo to be intelligently prioritized + +#### Features of echo + +- **Optimized Router:** Echo comes with a highly optimized HTTP router with zero dynamic memory allocation which smartly prioritizes routes. + +- **Scalable:** Echo makes it easy to build and organize robust and scalable RESTful API. + +- **Automatic TLS:** With Echo, we can automatically install TLS certificates from Let's Encrypt. + +- **HTTP/2:** With the HTTP/2 support feature echo is able to achieve a well-improved speed and a better user experience. + +- **Middleware:** It comes with much built-in middleware that a developer can use, and also allows a developer to define their own, this middleware can be set at root, group, or route level. + +- **Data Binding:** This feature provides support for data binding for HTTP request payload, which also includes JSON, XML, or form-data. + +- **Data Rendering:** This feature provides an API for sending various HTTP responses, including JSON, XML, HTML, files, and attachments. + +- **Templates:** Template rendering using any template engine. + +- **Extensible:** Customized central HTTP error handling. Easily extendable API. + +**Biggest drawback:** The echo framework can be maintained only by one developer and the code is updated infrequently. + +### Fast Http + +![Fasthttp image](/top-5-golang-framework/fasthttp-image.jpg) + +Fast HTTP server known to be up to 10 times faster than net/http, became the go-to for developers due to the limitations of net/http. In terms of optimization possibilities, the fast HTTP framework offers a quick HTTP server and client API. +With fast HTTP we can manage over 200K rps and over 1.5M concurrent keep-alive connections per physical server. + +#### Features of Fasthttp + +Fast HTTP comes with a lot of features which I will be listing a few and also a link to the full list. + +- Optimized for speed. Easily handles more than 100K qps and more than 1M concurrent keep-alive connections on modern hardware. +- Optimized for low memory usage. +- Easy 'Connection: Upgrade' support via RequestCtx.Hijack +- The server provides the following anti-DoS limits: +- The number of concurrent connections. +- The number of concurrent connections per client IP. +- The number of requests per connection. +- Request read timeout. +- Response writes timeout. +- Maximum request header size. + +[Here](https://pkg.go.dev/github.com/valyala/fasthttp) is a link to the full list of its feature. + +#### Bonus + +I have one bonus for you which is fiber + +### Fiber + +![fiber logo](top-5-golang-framework/fiber-image.png) +Fiber is another Golang framework that you can consider learning especially if you're new to Go and you're looking to start creating web applications quickly. + +Furthermore, if you have worked with Node.js and express then getting along with fiber won't be difficult since many methods and principles will seem very common to you. + +Fiber is built on top of the Fasthttp, which as we saw in the previous section is the fastest HTTP engine for Go. Inspired by Express it was designed with fast development, zero memory allocation, and performance in mind. + +#### Features of Fiber + +- Routing +- Middleware support +- Good documentation +- Supports a variety of templates +- Supports WebSocket which is useful for building chat systems. + +### Conclusion + +In this article, we looked at the top 5 Golang frameworks, based on GitHub stars. There are others on the list but we choose to go with the top 5. +You can check the link [here](https://github.com/mingrammer/go-web-framework-stars) for the full list, to see the other frameworks we didn't cover in this article. + +It is important to note that each of these frameworks functions better based on the use case, each of them comes with its own unique feature and some have the features lacking in other frameworks combined together. + +So I recommend choosing a framework based on the kind of project you want to build using this article as a guide. +I hope this article guides you to choose the right Goland framework for your next Go project.