News for hackers. Stuff that matters.
Re:Gadget: A smallish web framework for Go by bernatfp on Tuesday November 26, 2013 @10:37AM (#6801908)
As a fan of Flask/Bottle/Sinatra/Express style web frameworks I miss a Go framework that works in a similar fashion. Don't know of any better way to prototype APIs so quickly and with such a small mental effort.

Edit: Just discovered [Martini](https://github.com/codegangsta/martini), that's exactly what I wanted.

Re:Gadget: A smallish web framework for Go by codegangsta on Tuesday November 26, 2013 @10:40AM (#6801922)
Re:Gadget: A smallish web framework for Go by optymizer on Tuesday November 26, 2013 @05:09PM (#6804613)
> "Handlers are invoked via reflection"

That's where I say NO. go's reflect package is slow and a nightmare to use. Go's JSON parser, which uses reflect, is 2.5x slower than Node.js (in my own benchmarks [1]). And Go 1.1 was 3.5x worse that Node.js at parsing JSON. Again, those are my benchmarks, but they seem consistent with what other people are finding (from my Googling around).

I would not make this trade off, I would not use reflect on EVERY request, just so that my request handlers are compatible with http.HandleFunc. It almost seems silly to do that. That's why other frameworks (like Revel) are using custom Request objects.

However, I do understand why the author is emphasizing this feature. If your handlers are incompatible with http.HandleFunc (i.e. if they take a custom Request object), you need your own Router which invokes the handlers, and you need your own ServeMux, so you end up giving up on a lot of functionality from net/http. That's why Revel has a ton of custom objects that mirror what net/http has and it proxies method calls.

So you keep wondering: "why the hell am I writing so much seemingly unrelated code? I just want to add a 'user' property to each request, but now I've coded so many struct's and created so many files". It makes you feel unproductive and it bloats the code.

Again, I've made my choice, but you should be aware of such caveats and, of course, benchmark things yourself.

1) My benchmark results. For some charts, higher is better, for others, lower is better. Use your judgement. http://goo.gl/xfWFXo

Re:Gadget: A smallish web framework for Go by continuations on Tuesday November 26, 2013 @09:04PM (#6805742)
Your benchmark results look very different from that of the web framework benchmark:

http://www.techempower.com/benchmarks/#section=data-r7&hw=i7...

In that benchmark Go's JSON performance is almost 3x higher than that of Node.

Any reasons why there's such a big difference?

Re:Gadget: A smallish web framework for Go by optymizer on Wednesday November 27, 2013 @08:14AM (#6807841)
I think it's because they're measuring the rate at which Node.js and Go receive requests, process json, and reply as a single metric.

I measured the speed with which Go and Node.js decode/encode JSON, i.e. there is no network and web server involved, just json.Marshal()/json.Unmarshal() vs JSON.parse()/JSON.stringify()

I benchmarked the web server speed separately.

Re:Gadget: A smallish web framework for Go by DecemberWaltz on Tuesday November 26, 2013 @08:26PM (#6805595)
Do you have the source code for your benchmarks? Thank you.
Re:Gadget: A smallish web framework for Go by optymizer on Wednesday November 27, 2013 @08:38AM (#6807948)
Sure, I updated the spreadsheet with links to the code for each benchmark. BSD license. Please keep in mind these were quick and dirty. If you run any of them, please reply with your findings.
Re:Gadget: A smallish web framework for Go by losvedir on Tuesday November 26, 2013 @06:31PM (#6805056)
It looks really slick, and I'm considering switching over a go-backed JSON API to an Ember app I'm building to use it.

How's the performance? I'm a little afraid of the "reflection" boogeyman, but I don't have any experience to say what kind of impact we're talking about here.

I'm coming from Rails day-to-day, and a very light, compiled Go web backend is a refreshing change of pace. I'm leery of giving up the simplicity of net/http, but if it stays small maybe it's the way to go. Right now I'm popping in gorilla toolkit, though, so if martini is as "light touch" as that, I'd be up for using it.

Re:Gadget: A smallish web framework for Go by DecemberWaltz on Tuesday November 26, 2013 @08:28PM (#6805603)
I have not tried this yet, but https://github.com/benbjohnson/megajson
Re:Gadget: A smallish web framework for Go by recuter on Tuesday November 26, 2013 @11:16AM (#6802184)
I'm kind of amazed at the SLOC, ~600 lines for the whole thing. Flask is much bigger and depends on Werkzeug (~20K?), heck even Bottle doesn't come in under 1,000 lines. That is incredibly attractive.
Re:Gadget: A smallish web framework for Go by codegangsta on Tuesday November 26, 2013 @11:19AM (#6802208)
Yup I plan to keep it that way too. I believe there is enough flexibility in Martini to cultivate some great functionality around the martini-contrib repo. There is already some pretty awesome things landing there https://github.com/codegangsta/martini-contrib
Re:Gadget: A smallish web framework for Go by draegtun on Tuesday November 26, 2013 @03:44PM (#6804070)
Checkout Camping (Ruby) & Squatting (Perl). Both are web microframeworks that aim (when minimised) to fit at or under 4K characters.

Here's the squashed versions of...

- Camping (currently 4.031 kb over 55 lines) - https://github.com/camping/camping/blob/master/lib/camping.r...

- Squatting (currently 3.929 kb over 68 lines) - https://github.com/beppu/squatting/blob/master/lib/squatting...

Re:Gadget: A smallish web framework for Go by krakensden on Tuesday November 26, 2013 @02:55PM (#6803723)
bottle.py might be a better Python comparison, since they're more concerned about being small & standalone.
Re:Gadget: A smallish web framework for Go by bernatfp on Tuesday November 26, 2013 @11:06AM (#6802109)
Yeah just after posting my comment.

BTW, great work, that's exactly what I was looking for.

Re:Gadget: A smallish web framework for Go by gregchapple on Tuesday November 26, 2013 @03:04PM (#6803796)
+1 for Martini. Spent some time looking for a decent framework like this, and was delighted when I discovered it.
Re:Gadget: A smallish web framework for Go by taude on Tuesday November 26, 2013 @04:26PM (#6804344)
Thanks. As a Flask user myself, and sort-of interested in Go, I'm going to take a look at this. Thanks.