Developing Web Application in Google’s Go Language

A few weeks ago I started working on a MVC framework for Google’s Go language – I call it fastweb. The development was fun and it is going pretty well that I can now create some useful webapps with the current set of features:

  • it has its own fastcgi implementation – you basically configure apache/lighttpd to point to an external fastcgi server
  • basic request routing/dispatching
  • it uses a modified version of Go’s template package as the template engine, which is kind of a clone of json-template.
  • the “element” and “controller’s element” concept – elements are re-usable parts that you can embed in your view template
  • POST form parsing (both application/x-www-form-urlencoded and multipart/form-data)
  • file upload (multipart/form-data)

As shown in the project page, a controller can be as simple as:

package main

import (
        "fastweb"
        "os"
)

type Products struct {
        fastweb.Controller
        name string
        brand string
        features []string
        specifications []string
        image string
}

func (p *Products) View(id string) os.Error {
        if id == "ah64" {
                p.name = "RC Apache AH64 4-Channel Electric Helicoper"
                p.brand = "Colco"
                p.features = []string{
                        "4 channel radio control duel propeller system",
                        "Full movement controll: forward, backward, left, right, up and down",
                        "Replica design",
                        "Revolutionary co-axial rotor technology",
                }
                p.specifications = []string{
                        "Dimensions: L 16 Inches X W 5.5 Inches x H 6.5 Inches",
                        "Battery Duration: 10 min",
                        "Range: 120 Feet",
                }
                p.image = "/img/ah64.jpg"
        }
        return nil
}

func main() {
        a := fastweb.NewApplication()
        a.RegisterController(&Products{})
        a.Run(":12345")
}

Pretty cool huh?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: