Live data from Hacker News

Gadget: A smallish web framework for Go

redneckbeard.github.io

21–30 of 52 posts

Re: Gadget: A smallish web framework for Go

#21
post #5

Unlike Revel, you don't seem to have watch setup for .go files, which make sense since you want to keep it smallish. Curious on how other gopher trigger app restart from their editor of choice. Anyone have insight for setting up VIM+Tmux for Golang development that enable app restart from single key press? Sample .vimrc will be great.

Adding a watch system is not very complicate using `fsnotify`, I've done it for a toy blog app, so that it watches the `/posts/` folder for new Markdown, and the `/templates/` folder for modified templates.

I've even made it rewrite (eradicate) templates that don't compile (threats).

https://github.com/aybabtme/brog/blob/master/brogger/templat...

At this point, the code is kind of messy, so please overlook that. I also have a bare deployment on an t1.micro : http://www.antoine.im/

Re: Gadget: A smallish web framework for Go

#22

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.

Have you seen Martini? https://github.com/codegangsta/martini

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

#23
post #22

Earlier quoted context omitted.

Have you seen Martini? https://github.com/codegangsta/martini

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.

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

#24

Earlier quoted context omitted.

I just don't understand the argument that we should all just use HandlerFuncs for everything. Python and Ruby have stdlib HTTP facilities that are pretty good. They aren't nearly as nice as net/http, but you could totally build websites with them. People still have written lots of web frameworks, because it makes their lives easier. It lets them express programs in a simpler, higher-level way. I feel like this is eve…

> feel like this is even more valid now in 2013 since nearly anyone who's building websites has done so with one of those high-level frameworks, and they expect a similar experience. But in 2013 do I really want to use server side HTML tempalating? Why not just connect a webservice to a HTML/JS presentation layer like I am suggesting? If all you are doing is building a webservice then the abstractions beyond net/http…

You have a point, no pun intended. Focusing on serving up tidy endpoints does away with a lot of complexity (I call shenanigans on the performance argument, especially if you're using Go and not Python/Ruby) - the only unsolved technical debt with this approach would be making GoogleBot happy. If you don't need to care about making crawlers happy this can be great...

On the other hand, the complexity you're punting on needs to go somewhere, so now you'll need to muck about with something like Angular to make up for it. Difficult choices. It kind of continuously feels like we're on the edge of Nirvana with this stuff and something perfect in its elegance will emerge. I'm only 24 but this seems like a dangerous siren song to me... maybe we should all know better by this point, eh?

Re: Gadget: A smallish web framework for Go

#25

Earlier quoted context omitted.

If you don't want it then you don't want it. Both Gadget and Martini pretty clearly outline the value that they bring to the table. If that value proposition does not win you over then these frameworks are not for you. I personally have seen a great improvement in code simplicity, readability, and overall DRYness when projects are written using Martini. Choosing a framework isn't about following some sort of socially…

I'm glad you like these frameworks, and I not telling anyone not to use them. Like I said, I was just interested in hearing why I would want something like these frameworks which focus on server side templating, over a HTML/JS frontend + webservice approach. If you are just writing a webservice I think using Gorilla in addition to net/http is pretty much perfect.

shameless plug. Martini doesn't even have html template rendering out of the box. I originally built it because I wanted a better experience building webservices for Angular frontends :)

https://github.com/codegangsta/martini

You and I sir, are on the same wavelength

Re: Gadget: A smallish web framework for Go

#26

Earlier quoted context omitted.

I just don't understand the argument that we should all just use HandlerFuncs for everything. Python and Ruby have stdlib HTTP facilities that are pretty good. They aren't nearly as nice as net/http, but you could totally build websites with them. People still have written lots of web frameworks, because it makes their lives easier. It lets them express programs in a simpler, higher-level way. I feel like this is eve…

> feel like this is even more valid now in 2013 since nearly anyone who's building websites has done so with one of those high-level frameworks, and they expect a similar experience. But in 2013 do I really want to use server side HTML tempalating? Why not just connect a webservice to a HTML/JS presentation layer like I am suggesting? If all you are doing is building a webservice then the abstractions beyond net/http…

But in 2013 do I really want to use server side HTML tempalating?

Many people do yes. It may seem old-fashioned but when I load a web page I don't want to sit looking at a 'loading' message or a progress bar before I even see the content as json is turned into html, and I'd rather all the logic was server side and a flat page was served to a web client (browser).

I don't agree doing rendering server-side necessarily means a significant performance cost, or is harder to maintain or slower to develop, why do you think that is the case? Caching and a server-side framework can make things far faster and easier, depending on what you are doing, and raw speed of rendering is not often an issue nowadays anyway.

I'm not sure what the test you pointed to there was showing, because using Go to output json could be done with a framework too by just bypassing the framework, in exactly the same way. It hardly seems a relevant test, and there were other issues in those tests when I looked at them previously - like comparing wildcard routes in one test to hard coded ones in another. Comparing bare JSON production with go to JSON production with webgo (do people use webgo?) is hardly very useful or a fair comparison. It would be trivial to make those equal in speed and I suspect the diff will just be down to different routing and/or template rendering. In addition, I don't want clients to see JSON, so the rendering speed of that is pretty irrelevant, what matters to most people is when html finishes rendering.

It would be interesting to hear the reasons behind the string of assertions in your penultimate sentence, are you sure all types of app would benefit equally from your approach? Can you describe the advantages as you see them to this approach?

Re: Gadget: A smallish web framework for Go

#27

Earlier quoted context omitted.

I just don't understand the argument that we should all just use HandlerFuncs for everything. Python and Ruby have stdlib HTTP facilities that are pretty good. They aren't nearly as nice as net/http, but you could totally build websites with them. People still have written lots of web frameworks, because it makes their lives easier. It lets them express programs in a simpler, higher-level way. I feel like this is eve…

> feel like this is even more valid now in 2013 since nearly anyone who's building websites has done so with one of those high-level frameworks, and they expect a similar experience. But in 2013 do I really want to use server side HTML tempalating? Why not just connect a webservice to a HTML/JS presentation layer like I am suggesting? If all you are doing is building a webservice then the abstractions beyond net/http…

Use of gadget/template is totally optional. The _primary_ use case for Gadget is RESTful web services. That's why you can route to a resource, and have the appropriate controller methods hit by the correct HTTP verbs. The reason to provide support for HTML rendering on the server is no different than providing plaintext rendering: it's really really easy. It's almost free.

Re: Gadget: A smallish web framework for Go

#28

Earlier quoted context omitted.

I'm glad you like these frameworks, and I not telling anyone not to use them. Like I said, I was just interested in hearing why I would want something like these frameworks which focus on server side templating, over a HTML/JS frontend + webservice approach. If you are just writing a webservice I think using Gorilla in addition to net/http is pretty much perfect.

shameless plug. Martini doesn't even have html template rendering out of the box. I originally built it because I wanted a better experience building webservices for Angular frontends :) https://github.com/codegangsta/martini You and I sir, are on the same wavelength

Interesting, I'll have to play with it. Thanks for sharing.

You should consider adding benchmarks to that it is easy to compare martini to net/http. This will let you keep an eye on performance as you work on it and accept pulls.

Re: Gadget: A smallish web framework for Go

#29

Earlier quoted context omitted.

> feel like this is even more valid now in 2013 since nearly anyone who's building websites has done so with one of those high-level frameworks, and they expect a similar experience. But in 2013 do I really want to use server side HTML tempalating? Why not just connect a webservice to a HTML/JS presentation layer like I am suggesting? If all you are doing is building a webservice then the abstractions beyond net/http…

But in 2013 do I really want to use server side HTML tempalating? Many people do yes. It may seem old-fashioned but when I load a web page I don't want to sit looking at a 'loading' message or a progress bar before I even see the content as json is turned into html, and I'd rather all the logic was server side and a flat page was served to a web client (browser). I don't agree doing rendering server-side necessarily…

>It may seem old-fashioned but when I load a web page I don't want to sit looking at a 'loading' message or a progress bar

This is how bad implementations look to users, consider something like Gmail as a counter example however...

>would be interesting to hear the reasons behind the string of assertions in your penultimate sentence

Sure:)

>are you sure all types of app would benefit equally from your approach?

Of course I am not, I didn't make a that claim. I think most typical applications benefit, it has worked well for me. I was asking questions to understand the point of view I don't hold-

> Can you describe the advantages as you see them to this approach?

  In this approach: 
  Performance:
    1. Most assets are (server side) static
    2. They are pre-gzipped and stored in memory using a little reusable code I wrote.
    3. They are extremely cache friendly
  Better scaling:
    1. Only a fraction of the previous work happens server side... You using your users compute power.
    2. You are transfering less data.
  Faster to develop/easier to maintain:
    1. This way you have two differnt apps that happen to talk to eachother. This makes it easy to replace one or the other.
    2. Responsibilities are clearly defined. This makes brining new people up to speed easier and makes thingse asier to test, debug, etc.

Re: Gadget: A smallish web framework for Go

#30

Earlier quoted context omitted.

But in 2013 do I really want to use server side HTML tempalating? Many people do yes. It may seem old-fashioned but when I load a web page I don't want to sit looking at a 'loading' message or a progress bar before I even see the content as json is turned into html, and I'd rather all the logic was server side and a flat page was served to a web client (browser). I don't agree doing rendering server-side necessarily…

>It may seem old-fashioned but when I load a web page I don't want to sit looking at a 'loading' message or a progress bar This is how bad implementations look to users, consider something like Gmail as a counter example however... >would be interesting to hear the reasons behind the string of assertions in your penultimate sentence Sure:) >are you sure all types of app would benefit equally from your approach? Of co…

Thanks for the comments, it'd be easier to read if they weren't styled using pre!

Of course I am not, I didn't make a that claim.

Sorry, I should have phrased that differently as something like - perhaps not all types of app would benefit equally? I wasn't trying to put words in your mouth. I do think it's a little early to start asking why anyone would use server-side logic any more, there is room for both approaches :)

Perhaps if you are serving data which is text-only, static and fits well into json as you describe, and don't mind coding in Javascript, client-side is a better fit. If you have a lot of server-side data and editing/auth requirements (more of a CMS), and depend on heavily nested templates etc, server-side may be a better fit, though I'm sure it's possible to handle every type of website in theory using either system. There is also the question of which language you prefer to work in - personally I'd rather keep JS use to a minimum, as it's pretty gnarly.

Re the separation of concerns, yes this is a valid point and is something you gain from serving an API if you have a complex system, though it is possible to have a back-end behind a traditional web framework too, with one side being the API serving json or whatever and a separate user-facing service serving HTML.

I don't think speed or caching are a big problem with server-side frameworks nowadays though, and I'd rather use a language like Go than JS to produce web apps. Out of curiosity, which client-side frameworks are you using?

Post reply on HN