Monday, November 11, 2013

Creating a "Master Page" for your Go Web App

Most web apps share a common layout across different views. This common layout may include a header or a footer and even a navigation menu. Go's batteries-included standard library provides an easy way to create these common elements that can be reused in different views to create a "Master Page"-like effect.

This basic example demonstrates how:

Let's create a simple web app that has 2 views - a Main view and an About view. Both these views have the same header and footer sections.

The header template is defined in a file named header.html

The footer template is defined in a file named footer.html

The Main template is defined in a file named main.html

The About template is defined in a file name about.html

And here's the code that serves it up.

Each of the above templates has a name defined using the {{define "name"}} action. The Main and About templates include the header and footer templates using the {{template "name" .}} action. The '.' passes in the context to the named template. Now whenever the Main and About templates are executed, the header and footer will get included and inserted at the required location. That's all there is to it.

This is how the 2 views look.


This technique can also be used to create different layouts for different sections of the web app; for example, the administration section may look different from the user section. We just need to name our templates appropriately and include them where required.

Saturday, November 9, 2013

On Google's social layer.

Every once in a while, there is a major outrage over Google trying to "shove Google+ down our throats" as one more of its properties is integrated with Google+. There are accusations of Google wanting to inflate its active user count by "forcing" more people into Google+.

Google+ is one of the most misunderstood pieces of the Google puzzle. It is popularly considered as Google's wannabe answer to Facebook/Twitter and as yet another attempt at "getting" social.

Yet Google+ is more than just a mere social network. Google+ is literally Google + You (and your juicy details).

Google's goal is to become your perfect personal assistant - the ultimate handheld/wearable Star Trek computer. To do this, it has to understand your behavior/preferences. Google+ is a fabric that is being built around Google's other properties to do just that.

It is also important to understand this in the context of Google's business model. Google provides a number of services (mostly for free) in return for showing you advertisements (yes, there's no real free lunch). So, while attempting to become your Star Trek computer, it also has to stay relevant to advertisers - the people who spend money to keep it going.

Advertisers want to make sure that the money they spend, results in ads being shown where there is the greatest chance of success. People who see the ads (users like you and me) don't like ads, but would rather see relevant ads than irrelevant ones.

Understanding you, your behavior, preferences and social interactions helps Google achieve both objectives - becoming your Star Trek computer as well as becoming the ultimate advertising platform.

Judging from the outrage, a lot of people don't like this setup. The good thing about this, is that you don't have to use Google or any of its properties. There are alternatives. Be prepared to discover though, that these alternatives are not all that different, or if they are, are unviable from a long term perspective.