<story><title>A RESTful Micro-Framework in Go</title><url>http://dougblack.io/words/a-restful-micro-framework-in-go.html</url></story><parent_chain><item><author>mitchellh</author><text>This looks like a great resource! A bit of a rant (not directed at the person who wrote this, because the link at hand is great):&lt;p&gt;Writing APIs in Go is not the hard part. There are a ton of options for routing basic URLs to handlers. There are a few areas that are a nightmare, total total nightmare:&lt;p&gt;* SQL - The raw database&amp;#x2F;sql package in Go is very low-level. It is a terrible experience to use in a project that makes anything more than a handful of simple queries. I&amp;#x27;m not asking for an ORM, but it would really benefit the community if there was a SQLAlchemy style (the non-ORM part of it) library for Go. It should be MUCH easier to make basic queries to SQL and get out results.&lt;p&gt;* Templating - The built in &amp;quot;html&amp;#x2F;template&amp;quot; package is just not good enough for a web app when compared to something like Jinja (Python). &amp;quot;html&amp;#x2F;template&amp;quot; gets points for being simple, and actually its not a complaint against &amp;quot;html&amp;#x2F;template&amp;quot;: I think there just needs to be a more feature-packed templating package like Jinja for Go. &amp;quot;html&amp;#x2F;template&amp;quot; doesn&amp;#x27;t support things like inheritance, didn&amp;#x27;t even support comparison operators until Go 1.2, etc.&lt;p&gt;These two problems have made it so I&amp;#x27;ve pretty much given up web apps in Go for now. Services in Go are _amazing_. But if you&amp;#x27;re trying to get a full blown web app (again, not the point of the linked article above), then you&amp;#x27;re gonna have a bad time.</text></item></parent_chain><comment><author>hierro</author><text>We&amp;#x27;re about to release our Go web framework which, I think, implements all the features you&amp;#x27;re mentioning and a few more. We&amp;#x27;re aiming for a release in Q1, but getting everything cleaned up and writing good documentation is taking a bit longer than expected. Right now, our internal framework (codenamed Gondola, but subject to change), includes:&lt;p&gt;* A full ORM which generates tables from structs and allows relations between models, as well as a simple querying system based on Go functions which joins the tables automatically for you e.g.&lt;p&gt;&lt;pre&gt;&lt;code&gt;   memeId := base36.Decode(param)
   var meme *Meme
   var template *Template
   err := ctx.Orm().One(orm.Eq(&amp;quot;Meme|Id&amp;quot;, memeId), &amp;amp;meme, &amp;amp;template)
&lt;/code&gt;&lt;/pre&gt;
Meme declares a FK to Template, so the ORM automatically joins the tables and populates both pointers. Note that the ORM does not require the backends to be relational, so even when ATM we only have database&amp;#x2F;sql based backends you could write a backend for mongodb or rethinkdb.&lt;p&gt;* Inheritance based template system, with a declarative assets pipeline supporting compilation (e.g. it compiles coffescript to JS and less to CSS on demand - also pluggable). This is the base template from one of our apps:&lt;p&gt;&lt;pre&gt;&lt;code&gt;   {{&amp;#x2F;*
      jquery|if=~ie-gte-9: 2.0.3
      jquery|if=ie: 1.10.2
      bootstrap|fontawesome=4.0.3: 3.0.0
      styles|bundle: css&amp;#x2F;style.css, lightbox&amp;#x2F;css&amp;#x2F;lightbox.css
      scripts|top,bundle: js&amp;#x2F;modernizr.js, js&amp;#x2F;detectizr.js
      scripts|bundle: js&amp;#x2F;responsiveslides.js, lightbox&amp;#x2F;js&amp;#x2F;lightbox-2.6.min.js, js&amp;#x2F;site.js
      analytics|nodebug: {{ $Config.Analytics }}
   *&amp;#x2F;}}
    &amp;lt;!DOCTYPE html&amp;gt;
    ...
    {{ template &amp;quot;main&amp;quot; }}...
&lt;/code&gt;&lt;/pre&gt;
This server query 1.10 and 2.0 from Google&amp;#x27;s CDN, bootstrap and fontawesome from bootstrapcdn.com and bundles all our styles and scripts a CSS and a JS file. Then other templates can extend this one and override its blocks e.g.&lt;p&gt;&lt;pre&gt;&lt;code&gt;   {{&amp;#x2F;*
     extends: base.html
   *&amp;#x2F;}} 
   {{ define &amp;quot;main&amp;quot; }}...
&lt;/code&gt;&lt;/pre&gt;
(note that base.html could also define its own &amp;quot;main&amp;quot; block which would act as a default if you loaded base.html and it would be replaced by main.html&amp;#x27;s &amp;quot;main&amp;quot; block if you loaded &amp;quot;main&amp;quot;).&lt;p&gt;* Easy to use signed and encrypted cookies.&lt;p&gt;* Regular expression based URL routing.&lt;p&gt;* Functions for easily parsing input parameters.&lt;p&gt;* A development server which automatically rebuilds the source as it changes and reports compilation errors in the browser itself. While developing, runtime errors are also reported in the browser with complete backtraces and printing the values passed to each function. While running in production, those reports are sent by email to the project administrator(s).&lt;p&gt;* App-wide and low-level caching system with pluggable backends, currently supporting Redis and Memcache as well as a dummy backend for development.&lt;p&gt;* Form generator and validator from Go structs, with renderers for both Bootstrap and Foundation (renderers are also pluggable, so you could also write your own. We also support generating forms from multiple objects so you e.g. write an object which generates a captcha and include it in any form with a single line in code (in fact, we provide just that, but a simple numeric captcha a a full-blown recaptcha object). It also does automatic CSRF protection.&lt;p&gt;* A complete i18n system, which extracts strings from Go code and templates, generates .pot files which can be translated using any editor (or a specialized .po editor if you feel like it) and them compiles .po files back to Go code again. This makes packages with their translations &amp;quot;go-get-able&amp;quot;.&lt;p&gt;* Periodic and background tasks which can either be scheduled or just started from any web request.&lt;p&gt;* A configuration package which takes a struct and fills it by parsing an optional configuration file as well as command line flags.&lt;p&gt;* Support for administrative commands, which can be executed from the command line or started remotely.&lt;p&gt;* Support for pluggable apps. e.g. we do have a &amp;quot;users&amp;quot; app which provides user registration, authentication and social integration. This can be included in any other app with a couple of lines of code (one line for the import, another line to tell our main app to include it). Included apps can do a lot of stuff, like inserting code in every template rendered by the parent app, including external assets like images, styles or scripts and even rendering their own templates contained inside your parent&amp;#x27;s app base template.&lt;p&gt;* Last but not least, a minimal overhead (in the range of 100ns per request) profiling framework which lets you know how much time a request spent in the cache, the orm, the template, e.g... as well as seeing how much each operation took (e.g. you can check how much time a SELECT took and also perform an EXPLAIN on it). Users can also define their own events and profile them by instrumenting their code (it usually requires just a line of code per resource, to indicate its name). You can also profile a live server by using a command line app included in the framework.&lt;p&gt;We also have helper and utility functions for the more mundane stuff and basically everything you could expect from a web framework. We took inspiration from Django, Tornado and Rails and tried to take the best of them while building this framework (I used to contribute to Tornado back in the day). We&amp;#x27;ve been developing this internally for almost 2 years and it&amp;#x27;s now around 40KLOC of Go and a couple of K of coffescript, less and html.</text></comment>
<story><title>A RESTful Micro-Framework in Go</title><url>http://dougblack.io/words/a-restful-micro-framework-in-go.html</url></story><parent_chain><item><author>mitchellh</author><text>This looks like a great resource! A bit of a rant (not directed at the person who wrote this, because the link at hand is great):&lt;p&gt;Writing APIs in Go is not the hard part. There are a ton of options for routing basic URLs to handlers. There are a few areas that are a nightmare, total total nightmare:&lt;p&gt;* SQL - The raw database&amp;#x2F;sql package in Go is very low-level. It is a terrible experience to use in a project that makes anything more than a handful of simple queries. I&amp;#x27;m not asking for an ORM, but it would really benefit the community if there was a SQLAlchemy style (the non-ORM part of it) library for Go. It should be MUCH easier to make basic queries to SQL and get out results.&lt;p&gt;* Templating - The built in &amp;quot;html&amp;#x2F;template&amp;quot; package is just not good enough for a web app when compared to something like Jinja (Python). &amp;quot;html&amp;#x2F;template&amp;quot; gets points for being simple, and actually its not a complaint against &amp;quot;html&amp;#x2F;template&amp;quot;: I think there just needs to be a more feature-packed templating package like Jinja for Go. &amp;quot;html&amp;#x2F;template&amp;quot; doesn&amp;#x27;t support things like inheritance, didn&amp;#x27;t even support comparison operators until Go 1.2, etc.&lt;p&gt;These two problems have made it so I&amp;#x27;ve pretty much given up web apps in Go for now. Services in Go are _amazing_. But if you&amp;#x27;re trying to get a full blown web app (again, not the point of the linked article above), then you&amp;#x27;re gonna have a bad time.</text></item></parent_chain><comment><author>aktau</author><text>I&amp;#x27;m usually pretty anti-ORM and actually like low-level SQL interfaces (I guess because I did a short stint as an Oracle developer once, once you see what can be done with some custom SQL...). But for a recent sideproject of mine, I really didn&amp;#x27;t want to create a laborious interface to the database. I wanted something quick and dirty. I got something quick, and it doesn&amp;#x27;t feel dirty at all. It&amp;#x27;s called gorp: &lt;a href=&quot;http://github.com/coopernurse/gorp&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;coopernurse&amp;#x2F;gorp&lt;/a&gt;.&lt;p&gt;By the way, my sideproject is about getting financial data from sources like Yahoo Finance, Bloomberg, et cetera. You can find it here: &lt;a href=&quot;https://github.com/aktau/gofinance&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;aktau&amp;#x2F;gofinance&lt;/a&gt;</text></comment>