Total Pageviews

Sunday 25 May 2014

web.go-一个用go语言写web app的工具

web.go is the simplest way to write web applications in the Go programming language. It's ideal for writing simple, performant backend web services.

Overview

web.go should be familiar to people who've developed websites with higher-level web frameworks like sinatra or web.py. It is designed to be a lightweight web framework that doesn't impose any scaffolding on the user. Some features include:
  • Routing to url handlers based on regular expressions
  • Secure cookies
  • Support for fastcgi and scgi
  • Web applications are compiled to native code. This means very fast execution and page render speed
  • Efficiently serving static files

Installation

Make sure you have the a working Go environment. See the install instructions. web.go targets the Go release branch.
To install web.go, simply run:
go get github.com/hoisie/web
To compile it from source:
git clone git://github.com/hoisie/web.git
cd web && go build

Example

package main

import (
    "github.com/hoisie/web"
)

func hello(val string) string { return "hello " + val } 

func main() {
    web.Get("/(.*)", hello)
    web.Run("0.0.0.0:9999")
}
To run the application, put the code in a file called hello.go and run:
go run hello.go
You can point your browser to http://localhost:9999/world .

from https://github.com/hoisie/web