DEV Community

Edward Marinescu
Edward Marinescu

Posted on • Edited on

Top 6 web frameworks for Go as of 2017

Awesome Web Frameworks for Gophers

You may not need a web framework if you design a small application for yourself, but if you're going production then you definitely will need one, a good one that is.

And while you think that you have the necessary knowedge and experience, would you risk to code all of those features by yourself?
Do you have the time to find a production-class external package to do the job? Are you sure that this will be aligned with the rest of your app?

These are the serious reasons that drive even the best of us to use frameworks, we don't want to code all those necessary features by ourselves if someone else already did the hard work.

Introduction

Go is a rapidly growing open source programming language designed for building simple, fast, and reliable software. Take a look here to see which great companies use Go to power their services.

This article has all the necessary information to help developers learn more about the best options that are out there to develop web applications with Go.

The article contains the most detailed framework comparison that is out there, by comparing the the most known web frameworks from as many angles as possible: popularity, support and built'n features:

Beego: An open-source, high-performance web framework for the Go programming language.

Buffalo: Rapid Web Development w/ Go.

Echo: A high performance, minimalist Go web framework.

Gin: HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance.

Iris: The fastest web framework for Go in The Universe. MVC fully featured. Embrace the future today.

Revel: A high productivity, full-stack web framework for the Go language.

Popularity

Sorted by the popularity (stars)


https://github.com/speedwheel/awesome-go-web-frameworks/blob/master/README.md#popularity

Learning Curve


https://github.com/speedwheel/awesome-go-web-frameworks/blob/master/README.md#learning-curve

Great job by astaxie and kataras here, hopfully and the other frameworks will catch up with more examples, at least for me, if I switch to a new framework, that's the most resourceful place to quickly grasp as much information as possible. An example it's like 1000 words.

Core Features

Sorted by the most to less featured



https://github.com/speedwheel/awesome-go-web-frameworks/blob/master/README.md#core-features

The most known "Web frameworks" in Go are not really frameworks, meaning that:
Echo, Gin and Buffalo are not really (fully featured) web frameworks
but the majority of Go community thinks that they are.
Therefore they think that they are comparable with Iris, Beego or Revel,
because of that we have the obligation to include them into this list as well.

All of the above frameworks, except Beego and Revel, can adapt any middleware
that was created for net/http, some of those can do this with ease and others
with some hacking [even the pain is a choice here].
Enter fullscreen mode Exit fullscreen mode

Vocabulary

Router: Named Path Parameters & Wildcard

When you can register a handler to a route with dynamic path.

Example Named Path Parameter:

"/user/{username}" matches to "/user/me", "/user/speedwheel" etc
Enter fullscreen mode Exit fullscreen mode

The username path parameter's value is the "/me" and "speedwheel" respectfully.

Example Wildcard:

"/user/{path *wildcard}" matches to
"/user/some/path/here",
"/user/this/is/a/dynamic/multi/level/path" etc
Enter fullscreen mode Exit fullscreen mode

The path path parameter's value is the "some/path/here" and "this/is/a/dynamic/multi/level/path" respectfully.

Iris supports a feature called macros as well, can be described as /user/{username:string} or /user/{username:int min(1)}.

Router: Regex

When you can register a handler to a route with dynamic path
with filters some that should be passed in order to execute the handler.

Example:

"/user/{id ^[0-9]$}" matches to "/user/42" but not to "/user/somestring"
Enter fullscreen mode Exit fullscreen mode

The id path parametert's value is 42.

Router: Grouping

When you can register common logic or middleware/handlers to a specific group of routes that share the same path prefix.

Example:

myGroup := Group("/user", userAuthenticationMiddleware)
myGroup.Handle("GET", "/", userHandler)
myGroup.Handle("GET", "/profile", userProfileHandler)
myGroup.Handle("GET", "/signup", getUserSignupForm)
Enter fullscreen mode Exit fullscreen mode
  • /user
  • /user/profile
  • /user/signup

You can even create subgroups from a group:

myGroup.Group("/messages", optionalUserMessagesMiddleware)
myGroup.Handle("GET', "/{id}", getMessageByID)
Enter fullscreen mode Exit fullscreen mode
  • /user/messages/{id}

Router: All the above Mixed Without Conflict

This is an advanced, but useful feature that many of us hope that is supported by a router or a web framework, currently only Iris supports this in the Go world.

It means that something like /{path *wildcard} and /user/{username} and /user/static and /user/{path *wildcard} can be registered in the same router which can correctly matches without conflict by static paths (/user/static) or wildcard (/{path *wildcard}).

Router: Custom HTTP Errors

When you can reigster a handler for an "error" status code. An error http status code is a >=400 status code, i.e NotFound 404.

Example:

OnErrorCode(404, myNotFoundHandler)
Enter fullscreen mode Exit fullscreen mode

Most of the web frameworks above support only 404, 405 and 500 registration, but fully featured like Iris, Beego and Revel supports any status code or even any error code ( any error is supported by Iris only).

100% compatible with net/http

Means that you have:

  • the framework gives you a context with direct access to the *http.Request and http.ResponseWriter.
  • a way to convert an net/http handler to a specific framework's type of Handler.

Middleware ecosystem

When you don't have to wrap each handlers with middleware by your own, but the framework gives you a full engine to define the flow, globally or per route or per group of routes, i.e Use(middleware), Done(middleware) etc.

Sinatra-like API

Register in runtime handlers to routes for specific HTTP Methods (and path parameters).

Example:

.Get or GET("/path", gethandler)
.Post or POST("/path", postHandler)
.Put or PUT("/path", putHandler) and etc.
Enter fullscreen mode Exit fullscreen mode

Server: Automatic HTTPS

When the framework's server supports registering and auto-renewing the SSL certifications to manage the SSL/TLS incoming connections (https). The most famous automatic https provider is the letsencrypt.

Server: Gracefully Shutdown

When pressing CTRL + C to close your terminal application; the server will close itself gracefully, waiting for some connections to finish their job (with a specicified timeout) or fire a custom event to do cleanup (i.e database Close).

Server: Multi Listeners

When tje framework's server supports registering custom net.Listener or serve a web applications using more than one http server and address.

Full HTTP/2

When the framework supports HTTP/2 with https and the server Push feature with ease.

Subdomains

When you can register routes per x,y subdomains directly from your web application.

secondary menas that this is not supported by the framework as a feature but you can still do it by starting multiple http servers, the downsides of this is that the main app and subdomain are not connected and is impossible to share logic between them by default.

Sessions

When http sessions are supported and ready to use inside your specific handler(s).

  • Some of the web frameworks supports back-end database to store the sessions so you can get persistence between server restarts.
  • Buffalo uses the gorilla sessions, which are little bit slower than the rest of the implementations.

Example:

func setValue(context http_context){
    s := Sessions.New(http_context)
    s.Set("key", "my value")
}

func getValue(context http_context){
    s := Sessions.New(http_context)
    myValue := s.Get("key")
}

func logoutHandler(context http_context){
    Sessions.Destroy(http_context)
}
Enter fullscreen mode Exit fullscreen mode

Wiki: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#HTTP_session

Websockets

When the framework supports websocket communications protocol. The implementations are different.

You should search their examples to see what suits you. My co-worker who tried all of those told me that Iris implements the most featured webosocket connections with the easier API compared to the rest.

Wiki: https://en.wikipedia.org/wiki/WebSocket

View (aka Templates) Embedded Into App

Normally you have to transfer all of your template files side by side with your web application's executable file. Embedded Into App means that the framework supports integration with go-bindata so the final executable file contains the templates inside it, represented as []byte.

What is a view engine

When the framework supports template loading, custom and built'n template functions to save our lives on critical parts.

View Engine: STD

When framework supports loading templates via the standard html/template parser.

View Engine: Pug

When framework supports loading templates via a Pug parser.

View Engine: Django

When framework supports loading templates via a Django parser.

View Engine: Handlebars

When framework supports loading templates via a Handlebars parser.

View Engine: Amber

When framework supports loading templates via an Amber parser.

Renderer: Markdown, JSON, JSONP, XML...

When the framework's context gives you an easy way to send/and customize a response of various content types of with ease.

MVC

Model–view–controller (MVC) is a software architectural pattern for implementing user interfaces on computers. It divides a given application into three interconnected parts. This is done to separate internal representations of information from the ways information is presented to, and accepted from, the user. The MVC design pattern decouples these major components allowing for efficient code reuse and parallel development.

  • Iris supports the full MVC features, can be registered at runtime.
  • Beego supports only method and models matching, can be registered at runtime.
  • Revel supports methods, path and models matching, can be registered only via a generator (a different software that you have to run to build your web application).

Wiki: https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

Caching

A web cache (or HTTP cache) is an information technology for the temporary storage (caching) of web documents, such as HTML pages and images, to reduce server lag. A web cache system documents passing through it; subsequent requests may be satisfied from if certain conditions are met.[1] A web cache system can refer either to an appliance, or to a computer program.

Wiki: https://en.wikipedia.org/wiki/Web_cache

File Server

When you can register a (physical) directory to a route which will serve the files of this directory to the client automatically.

File Server: Embedded Into App

Normally you have to transfer all static files (like assets; css, javascript files...) along with the application's executable file. Frameworks that support this feature gives you the chance to embed all those data inside your application, represented as []byte, their response time is also faster because server can serve them directly without looking up for the file in a physical location.

Response can be Modified Many times through lifecycle before sent

Currently only Iris supports this via built'n response writer in its http_context.

When framework supports this you can retrieve or reset or modify the written status code, body and headers before sent to the client (in net/http based web frameworks this is not possible by default because the body and status code cannot be retrieved or changed when written).

Gzip

When you're inside a route's handler and you can change the response writer in order to send a response using the gzip compression, the framework should take care of the sent headers, it should reset the response write back to normal if any error occurs and also it should be able to check if gzip is supported by client.

gzip is a file format and a software application used for file compression and decompression

Wiki: https://en.wikipedia.org/wiki/Gzip

Testing Framework

When you can test your HTTP using a specific framework library, that its work is to help you write better tests with ease.

Example (currently, only Iris supports that)

func TestAPI(t *testing.T) {
    app := myIrisApp() 
    tt := httptest.New(t, app)
    tt.GET("/admin").WithBasicAuth("name", "pass").Expect().
    Status(httptest.StatusOK).Body().Equal("welcome")
}
Enter fullscreen mode Exit fullscreen mode

myIrisApp returns your imaginary web application,
it has got a GET handler for /admin which is protected by basic authentication.

The above simple test checks if /admin responded with Status OK and authentication passed with specific username and password and its body is "welcome".

Typescript Transpiler

Typescript goal is to be a superset of ES6 that, in addition to all the new stuff that the standard is defining, will add a static type system. Typescript has also a transpiler that converts our Typescript code (i.e. ES6 + types) to ES5 or ES3 javascript code so we can use it in today browsers.

Online Editor

With the help of the online editor you can Quickly and Easy compile and run go code online.

Logging System

Custom logging System thaty extend the native log package behavior by providing useful features like color coding, formatting, log levels separation, different logging backends, etc.

Maintenance & Auto-Updates

Inform users of your framework of "on the fly "updates in a non-intrusive way.

This article was originally posted on: https://medium.com/@MarinescuEdwar1/top-6-web-frameworks-for-go-as-of-2017-23270e059c4b

See ya!

Thank you for reading, if you’d like this article please react with an emoji!"

Top comments (12)

Collapse
 
foresthoffman profile image
Forest Hoffman

I'm going to bookmark this for the future. I've been curious about what other frameworks were available in the Go world, and Iris is one that I haven't heard of before. It seems to be the one to use (IMO) since it has such a broad feature set!

Thanks, Edward!

Collapse
 
thedestro profile image
the-destro

There seems to be some extremely negative reactions to the development process to Iris and the author doing some shady commits. Thoughts on this?

Collapse
 
speedwheel profile image
Edward Marinescu • Edited

Hello the-destro, thank you for your time reading this article, however...

It seems that you're a new member on dev.to, and this is the only article that you commented on. I'm glad that this article drives people like you to create new accounts & comments, even if a very small majority of the arguments are completely out of scope.

I'm watching all of these web frameworks that were mentioned here, and I can assure you that none of them have any "shady" commits.
The "shady" thing here up to now is your presence and comment, do you have any reasonable proof or just throw empty accusations?

We're in 2017, github exists, and every framework has its code public.
Please take some time to check all the frameworks by yourself and write down those supposedly "shady" commits, or even better, try to fix them by submitting a PR.

We would all here really appriciate more if you would just tell us about what do you like most in these web frameworks instead of just throwing empty accusations.

All the authors that worked hard to make these products and the people that contributed to them also did an amazing job that required hard work to craft these amazing products, and we should appreciate that.

I just want to inform you that any previous drama that have might occured; doesn't exist now, there were just personal vendettas that have nothing to do with any framework or commits, stop living in the past and enjoy the awesome frameworks that we have here and try to make something useful for the go community.

Collapse
 
thedestro profile image
the-destro

Easy there. Yes, my account is new but I'm not trying to troll. I was merely interested in Iris and started doing some searches in google and on reddit and saw some blog posts about some issues. Since the posts came up with not a lot of searching I figured it would be good at least address it(since others would be seeing the same thing I am). I understand that sometimes things can get a wee bit toxic in OSS. I can provide the links if you are interested but I would prefer to not pollute your comment section with them if the claims are baseless or out of date but the first post was the fourth search result in google.

Thread Thread
 
speedwheel profile image
Edward Marinescu

Yes, I was talking about this search result that you mentioned, it's fake.

The writer of that article has a great impact on creating new accounts and spamming his link in articles like mine, I've seen that with my own eyes, so don't believe him, he has a personal vendetta with the iris author and we should keep ourselves out of it.

Peace!

Thread Thread
 
dlsniper profile image
Florin Pățan

I wasn't going to comment until I saw this thread. Tell me how I'm creating those fake accounts? Is there any shred of evidence of that?
I actually have further proof that's not public to back up the reality, what do you have?
I'm tired of people tarnishing my name like that. Show me your proof and if it's real, I'll apologize for it. Or do you think this account is fake as well?

Collapse
 
palumacil profile image
Dan Wolf

I think the reference is to Iris deleting history and force pushing into master. It isn't shady in terms of having a virus or bad code embedded, but I don't trust a project that rewrites commits of contributors in a way that doesn't really have a benefit and could damage use of tools such as Glide and others besides offending the contributors. If I had a need for Iris, I might still try it and just not contribute. However, I tend to use the standard lib for web in Go anyway.

Collapse
 
valtism profile image
Dan Wood • Edited

Thanks for bringing this up. I thought it was strange for this article to have such a clear bias towards Iris. Edward Marinescu is a contributer to the Iris project, which would have been fine if he had disclaimed this right at the top of the article.

Reading his very dismissive reply to you made me look deeper into this.
reddit.com/r/golang/comments/57tmp...
reddit.com/r/golang/comments/57w79...

I should point out now that I don't even use Go.

Anyway, I feel like this article should not be published here for the time being. It feels very wrong, and the OP doesn't seem very friendly.

Collapse
 
maestromac profile image
Mac Siri

Thank you for pointing this out.

Collapse
 
andreeaforce profile image
Andreea • Edited

Nice comparison. Iris rulz!

Collapse
 
avelino profile image
Thiago Avelino

In this link has more web framework (and toolkit) github.com/avelino/awesome-go#web-...

Collapse
 
iphuong profile image
Phil

Do we have any update as for current ending of 2018?