Why you should leave Gorilla and start using Fiber instead

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.

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.

app.Use(limiter.New())

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.

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

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Francesco Pastore

Francesco Pastore

39 Followers

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