gobyexample/066-http-server-routing.go
Mark McGranaghan 354a9d862f reorder
2012-09-21 07:54:20 -07:00

26 lines
517 B
Go

package main
import ("net/http"; "github.com/bmizerany/pat"; "fmt")
func hello(w http.ResponseWriter, req *http.Request) {
fmt.Fprintln(w, "hello " + req.URL.Query().Get(":name"))
}
func main() {
p := pat.New()
p.Get("/hello/:name", http.HandlerFunc(hello))
http.ListenAndServe(":5000", p)
}
// == todo
// consider gorilla-web
// defaults
// fallthroughs
// not found
// == running
// $ go get github.com/bmizerany/pat
// $ go run xx-http-server-routing.go
//
// $ curl -i http://127.0.0.1:5000/hello/gopher