Wednesday, February 12, 2014

Go CMS for Google Apps Engine



Not so long ago I've starting digging into Go language and found it very attractive for server-side development. The reasons are:

  1. It is fast ("near C performance")
  2. It is garbage collected
  3. Syntax is though little bit strange (comparable to Dart), but still quite easy to learn
  4. Easy to start
Also Go is supported by Google Apps Engine.

Speaking about performance, I should mention cost. If you're in "cloud", then you should think about "cost per request" - how much resources were used to serve request. So if application is faster, it should be cheaper in case if you're using real "cloud" platform, such as GAE that can automatically scale your application.

Also because Go in compiled language, instance startup is much faster then Java/Python.   

The Idea

So if there is infrastructure for good scalable application, why not to create something generic that can use power of cloud platform? The idea was to create simple CMS (Content Management System), that:
  • Would store its templates in DataStore. File names would be keys, so they could be easily fetched/updated
  • Would store its data in DataStore (such as sections of the site, any other shared information)
  • Would use memcache service for caching compiled templates
  • Would use BlobStore for storing assets (images, etc)
  • Would support "development" mode, where files could be fetched from local folder. In production, zip file with content is imported into datastore/blobstore.

Served Web Site structure

The "source" web site (web site, that users would see) will contain:
  1. Static assets (images, stylesheets)
  2. Templates (parsed by Go's html/template package
  3. Data - I've decided to make is simple, so it is just pure CSV files
Here is a test web site, that I've used when implemented this idea:

As you can see, templates can include other templates: 
Here should be another template: {{template "another.html"}}

Everything inside 'data' folder is available to template like {{range $index, $element := .}}


Now there is very very ugly quick-and-dirty implementation I've wrote on a weekend:

In case of update, ut fetch last version of test web site from GitHub, import it and serve.

Now code is totally not structured - I was focusing to make a workable proof of concept. 

Deployed application you can find at:

Though it is really draft version, but at least it could be a starting point for implementing this idea.


  1. Structure code
  2. Add administration panel
    1. To be able to upload any .zip file with web site structure
    2. Configure url of updating
    3. Generation of some random URL for updating to be able to configure github hook for updating web site
    4. On development server switch between file/datastore storage
    5. Add some simple way to modify templates/data
    6. Export to .zip file
  3. Make "development" and "production" more generic (introduce interfaces?)

No comments: