Five web frameworks for Go

Francesco Pastore
4 min readFeb 9, 2023

--

Go is becoming one of the most widely used languages for creating APIs because of its simplicity and speed. In fact, compared to other languages such as Python or Javascript, a Go program is strongly and statically typed, and compiled directly, allowing for higher performance.

There are many web frameworks available for Go, in this article we will look at five of the most popular ones.

Gin

Gin is a highly popular web framework (66K stars on Github!) for the Go programming language, known for its simplicity and speed. Its popularity makes it a common choice for new projects with a long-term vision.

Gin provides a variety of interfaces and structures to simplify development, such as the specific gin context and a streamlined middleware structure. However, it may take some time for developers familiar with the standard net/http package to fully understand and utilize all of Gin’s features.

Pro

  • Fast and lightweight
  • Active community

Cons

  • Different than net/http
  • High learning curve
package main

import "github.com/gin-gonic/gin"

func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run() // listen and serve on 0.0.0.0:8080
}

Fiber

Fiber is a web framework for Go that is built on the fasthttp package, making it faster than other frameworks. However, this also comes with some drawbacks.

Because fasthttp is relatively new and not fully developed like the net/http package, currently it has several shortcomings, such as support for HTTP/2. If you are considering using this framework, it is important to consider whether the features provided are sufficient for your project needs.

Pro

  • Fast
  • Well documented
  • A lot of middlewares available

Cons

  • No HTTP/2 support
  • fasthttp is not fully completed as net/http
package main

import "github.com/gofiber/fiber/v2"

func main() {
app := fiber.New()

app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World 👋!")
})

app.Listen(":3000")
}

Go Chi

Go Chi is a less well-known web framework for Go, but its simplicity, lightweight structure, and speed make it a solid choice for web development. Also, its similarities to the now-archived Gorilla/mux project have made it a popular substitute.

The framework has well-written documentation and a variety of out-of-the-box middlewares such as JWT authentication, logging, and rate limiting. All of these features make Chi a good option for your next web project.

Pro

  • No external dependencies
  • Fully compatible with standard net/http package but…

Cons

  • … sometimes could be too verbose
  • Maintenance is not high at the moment.
package main

import (
"net/http"

"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)

func main() {
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World!"))
})
http.ListenAndServe(":3000", r)
}

Echo

Echo is a web framework for Go that is designed for high performance and ease of use. It is built on top of the net/http package and a structure very similar to Gin.

Echo also provides a wide range of built-in middleware for tasks such as logging, recovery, and CORS, as well as support for custom middleware. It is also extensible and has support for template rendering, WebSockets, and HTTP/2.

Pro

Cons

  • Not so popular as Gin
package main

import (
"net/http"

"github.com/labstack/echo/v4"
)

func main() {
e := echo.New()
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
e.Logger.Fatal(e.Start(":1323"))
}

Revel

Revel is a web framework that is built around the Model-View-Controller architecture. This makes it a great choice for projects that adhere to this design pattern, but it may not be the best fit for others.

Additionally, Revel offers hot reloading and an excellent documentation. However, it lacks some important elements for a MVC framework like an ORM or an advanced template engine.

Pro

  • Hot reloading
  • Good documentation
  • MVC support but…

Cons

  • … if you don’t use MVC it could be troublesome
  • ORM must be installed manually if needed
  • Few middlewares available (what about a rate limiter or a jwt auth middleware?)

I hope this article has been useful for your next Go project. There are many web frameworks out there; here we have reviewed just five of the most popular ones.

--

--

Francesco Pastore

An engineering student in Milan and a web developer for an IT company. Write about programming and cybersecurity topics.