from Hacker News

Build Your Own Web Framework in Go

by tibastral2 on 11/14/14, 10:32 AM with 36 comments

  • by valevk on 11/14/14, 12:22 PM

    A framework calls your code, a library is called by your code.

    In the long run, when you start a web application using packages like "net/http" and the gorilla toolkit, sooner or later it becomes framework-like, because you start to group your code together, you refactor it and make it easiliy extendable _for the app you are writing_. So, every app becomes a framework on it's own. And what I like about Go is the fact, that building such mini framworks is easy, and does not take much time - but the most important aspect is, that you don't need a huge framework that does all the things.

  • by TeeWEE on 11/14/14, 12:01 PM

    I kind of disagree with this article. With go its so easy to get started with http that most of the time you dont even need a framework. If you do, most good frameworks use the following function as a common basis:

      func(http.ResponseWriter, *http.Request)
    
    
    I started with barebones http, then used gorilla, and later started using negrioni.

    Any new library with uses this function helps me.

    So in the end: you dont need a framework, but libraries are nice.

    Note: My api is a simple json based rest service.

  • by anonfunction on 11/14/14, 11:32 AM

    As someone learning Go and coming from scripting languages this is a great introductory course. I want my APIs to be fast and Go seems to be the best language for that. Finding a middleware solution (negroni) was key for me to feeling productive.
  • by al2o3cr on 11/14/14, 11:49 AM

    Yes, do make your own framework. And don't leave any documentation either. Hell, invent your own language while you're at it.

    It'll make the "should we throw this code out" discussion WAAAAY easier in five years.

  • by fingerprinter on 11/14/14, 2:40 PM

    One of the values in a framework, particularly in Go's case at the moment, is a curated set of libraries and middleware. Since this doesn't exist the cost/effort is high for people looking to enter. It is likely too high for many.

    Put it another way, Django and Rails would never have gotten as popular were it not for their 'batteries included' approach. Sure, Sinatra and Flask came, but they came after.

    IMV, Go needs a Django/Rails if it is going to be a webframework. If not, if Go is destined for the API layer, it is probably fine with what it has now.

  • by pbobak on 11/14/14, 12:51 PM

    The question is: Should you build a web framework in Go?
  • by vincentriemer on 11/14/14, 1:24 PM

    And as expected there's no mention of interacting with a database. The lack of a decent orm is the only thing keeping me from using Go for some side projects.
  • by hanief on 11/14/14, 12:37 PM

    Do we need another framework? For learning, sure. But for production, it's better if we contribute to existing framework instead. Relevant XKCD: http://xkcd.com/927/
  • by StevePerkins on 11/14/14, 12:51 PM

    The original source talks at length about why you shouldn't use the Martini web framework, and links to another post where Jeremy Saenz (Martini's author) more or less disavows his creation (http://blog.codegangsta.io/blog/2014/05/19/my-thoughts-on-ma...). That's an interesting read, I'm surprised that I missed it earlier this year.

    I'm also surprised to read that Jeremy has written a more idiomatic successor framework... and named it "Negroni" (http://negroni.codegangsta.io). I don't know if I'm being too hyper-sensitive as a contemporary American, but is this just absolutely cringe-worthy to anyone else? I don't think I could evangelize this at work for that simple reason.

    "Oh hey, go check out the 'Negro' framework! It's written by the guy who goes by 'Code Gangsta', and you can read about it on his blog in between YouTube clips of him rapping." (yes, seriously)