Why you should leave Gorilla and start using Fiber instead

Francesco Pastore
3 min readNov 12, 2022

Gorilla is one of the most used Go libraries to develop REST API. It is very simple to use and it makes the standard net/http library more accessible.

In a big project, it could help to use a more clean and optimized framework that hides unuseful complexity. This is where Fiber can help!

Fast, fast, and again fast!

On the homepage of the Fiber documentation, you can see a comparison between the most common Go frameworks like Gin, Martini, and Negroni. Fiber is one of the best, thanks to the fasthttp package under the hood that is much faster than the standard net/http package.

fasthttp package has the best performance

The documentation is well written, yes it is possible!

If you have developed with Go for some time you have already accepted that the language is relatively new. So, also the libraries that have been made.

Usually, the documentations are a work in progress and there is not enough information to use the library properly.

Fortunately, this is not the case. The Fiber docs contain everything fundamental you could need and it is really well written.

The homepage of the official Fiber docs

Middleware in one line

If you take a look at the documentation of Fiber you can see that there are a lot of middlewares available.

For example, to add a rate limiter to your app you have to simply add this line.

app.Use(limiter.New())

A rate limiter will be added to your app with the default settings. With a single line your worries are at ease.

One context to rule them all

Usually, you have to manage a lot of parameters like an http request and response, a parsed token, or other additional stuff your logic could need. Fiber simplify this by using a single variable called Context where everything is put in it. Your function will have only to take as input a parameter and it will have access to everything it could need.

app.Get("/", func (c *fiber.Ctx) error {
c.AllParams()
c.Cookies("name")
c.IPs()
c.Query("order")
// ...
return c.Send([]byte("Hello, World!"))
})

Error handling is a piece of cake.

Your app should return a valid response even if an error occurs. Managing them could be difficult, but even for this problem Fiber has a solution.

You can return a specific fiber error with a status code and a message and everything will be taken care of by Fiber itself. Like a piece of cake!

app.Get("/", func(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusServiceUnavailable, "On vacation!")
})

I hope that you will give a chance to Fiber for your next project. Let me know if you like it!

--

--

Francesco Pastore

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