From 62d61b1b86d7a131b2428da02efa0967a41bafbd Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Wed, 19 Sep 2012 22:54:00 -0700 Subject: [PATCH] routing --- README | 1 - src/xx-http-server-routing.go | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/xx-http-server-routing.go diff --git a/README b/README index d501de2..57155f6 100644 --- a/README +++ b/README @@ -40,7 +40,6 @@ gobyexample.com signups = topics * web app - * routing * serve static files * string formatting * mongo diff --git a/src/xx-http-server-routing.go b/src/xx-http-server-routing.go new file mode 100644 index 0000000..d9c508d --- /dev/null +++ b/src/xx-http-server-routing.go @@ -0,0 +1,19 @@ +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) +} + +// == running +// $ go get github.com/bmizerany/pat +// $ go run xx-http-server-routing.go +// +// $ curl -i http://127.0.0.1:5000/hello/gopher