Any Pylon/Flask/Django like web framework for Golang and Any Tornado/Twisted like framework for Golang?

3,042 views
Skip to first unread message

Sean Bigdatafun

unread,
Jul 9, 2014, 5:06:30 PM7/9/14
to golan...@googlegroups.com
Any thing widely adopted in Go community for web tier? The following factors should be the primary consideration (at least for me):
  - separate of concern, i.e., providing a high quality MVC framework (URL routing is normally a one-liner, see the example below)
  - easy way for authentication ( the web programmers normally use one liner, see the example below)
  - other things I missed here, more discussion / comments are welcome

Here is a Flask (Python) example:
@app.route('/secret_page')  # one liner for URL routing
@login_required             # one liner for authentication
def secret_page():
    # My service logic...
    pass

As one of the sweet spots for Golang is its concurrency capability, Tornado/Twisted like framework can handle async request much efficiently (but still programming them needs a certain learning curve). The framework I'd like to try out in Go is the one that give me programming friendliness as I described above using Flask code as example (i.e., MVC and sequential logic thinking), yet giving me the async web request serving capability (hopefully with same friendliness).



Matt Silverlock

unread,
Jul 9, 2014, 7:48:41 PM7/9/14
to golan...@googlegroups.com
Go has a "built in" framework in the way of its net/http (http://golang.org/pkg/net/http/) package—think Ruby's Rack interface on steroids.
  • Requests are served concurrently by default (each request lives in its own goroutine)
  • Routing is easy:
package main
import "net/http"
func main() {
    r := http.NewServeMux()
    r.HandleFunc("/", IndexHandler)

    http.ListenAndServe(":8000", r)
}
func IndexHandler(w http.ResponseWriter, r *http.Request) {
    // Do whatever you'd like here - e.g.
    w.Write([]byte("Hello World"))
}
    

  • Everything is centered around the http.Handler interface - you can make a custom handler type that returns a status code and an error, and write a ServeHTTP() method (to satisfy the interface) that handles the error and serves a standard error page based on 404|500|etc
  • There's toolkits and micro-frameworks like Gorilla (http://www.gorillatoolkit.org/), Goji (https://goji.io/) and gocraft/web (https://github.com/gocraft/web/) that give you options for improved routing (named params), request contexts (passing data alongside a request, like Django's request.META dict), sessions and other middleware.
  • Go does not include any "standard" middleware like Flask might, but that's because Go typically aims to be composable (i.e. you're the glue). But thanks to the aforementioned http.Handler, it's easy to write stuff and share it: gorilla/handlers has some default logging & gzip handlers that work with net/http (and anything that respects http.Handler) and I can plug my own little project that does HTTP Basic Auth: https://github.com/goji/httpauth
What Go might not give you—because the community is (mostly) focused on modular components—is something that's "kitchen sink" like Django. If you're trying to get a CMS or news site out the door in < 6 months and don't need the performance that Go gives you any time soon, then Django is probably going to help you get to your MVP faster.

Go, however, is likely going to be easier to maintain in the long run—the "productivity" (hate that term...) vs. performance pay-off is very high. Most of the "frameworks" are closer to something like Bottle or Pyramid than Django or Rails (and you'll find most here will agree that that's a positive thing).

Hope that helps.

Justin Israel

unread,
Jul 9, 2014, 7:49:50 PM7/9/14
to Sean Bigdatafun, golang-nuts

Wasn't beego inspired by Tornado and Flask?
http://beego.me/docs/intro/

I've been using Martini (even if some people don't like the reflection magic) and have liked it so far.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sean Bigdatafun

unread,
Jul 9, 2014, 8:29:53 PM7/9/14
to golan...@googlegroups.com
Thanks first, and next follow up questions.

After quickly went through these micro framework's examples, I got the impression that I don't need two sets of frameworks to handle 
  -- ORM like apps (synchronous request/response, normally handled by Flask/Django)
  -- and Chat like apps (lots of open connections, normally handled by frameworks like Tornado/Twisted).

Instead, with these Go frameworks (or even directly use http://golang.org/pkg/net/http/), I don't need to change my thinking back and forth because I just view each connection as a linear logic (and that linear logic lives in a goroutine).

Is the above understanding near the truth?

Matt Silverlock

unread,
Jul 9, 2014, 8:32:36 PM7/9/14
to golang-nuts
That’s correct: you write synchronous code and Go’s net/http can handle the rest.

If you make sure that you’re not accessing global state (or if you are, that it has locks/is designed to be used that way) it’s hard to really mess things up.


--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/r8zAyo3wyvM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.

Justin Israel

unread,
Jul 9, 2014, 8:35:31 PM7/9/14
to Matt Silverlock, golang-nuts
Someone was just yesterday asking a question on StackOverflow about choosing Dart vs Go for their backend server, and I was trying to explain the same conclusion you had just came to, about how in Go you don't have to think about that Tornado/Twisted callback/async approach in order to preserve the concurrency across the application. 


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

andrewc...@gmail.com

unread,
Jul 9, 2014, 8:54:25 PM7/9/14
to golan...@googlegroups.com
Go doesn't require async io because it doesn't use a 1 to 1 mapping of thread to goroutine. It was designed to avoid some of the problems associated tornado/twisted async stuff, so i don't think you will really find Go people doing that.
Reply all
Reply to author
Forward
0 new messages