From 360105bc6416f1232526a27d1aaa25300bbf24c5 Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Sun, 23 Sep 2012 12:17:57 -0700 Subject: [PATCH] updates --- .../066-http-server-routing.go | 25 ------------------- .../http-server-routing.go | 21 ++++++++++++++++ .../http-server-routing.sh | 4 +++ ...namic.go => http-server-static-dynamic.go} | 17 ++++--------- .../http-server-static-dynamic.sh | 6 +++++ ...select.go => http-server-static-select.go} | 15 ++++------- .../http-server-static-select.sh | 7 ++++++ 7 files changed, 48 insertions(+), 47 deletions(-) delete mode 100644 066-http-server-routing/066-http-server-routing.go create mode 100644 066-http-server-routing/http-server-routing.go create mode 100644 066-http-server-routing/http-server-routing.sh rename 067-http-server-static-dynamic/{067-http-server-static-dynamic.go => http-server-static-dynamic.go} (60%) create mode 100644 067-http-server-static-dynamic/http-server-static-dynamic.sh rename 068-http-server-static-select/{068-http-server-static-select.go => http-server-static-select.go} (65%) create mode 100644 068-http-server-static-select/http-server-static-select.sh diff --git a/066-http-server-routing/066-http-server-routing.go b/066-http-server-routing/066-http-server-routing.go deleted file mode 100644 index 469179e..0000000 --- a/066-http-server-routing/066-http-server-routing.go +++ /dev/null @@ -1,25 +0,0 @@ -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 diff --git a/066-http-server-routing/http-server-routing.go b/066-http-server-routing/http-server-routing.go new file mode 100644 index 0000000..a1a585f --- /dev/null +++ b/066-http-server-routing/http-server-routing.go @@ -0,0 +1,21 @@ +// ## HTTP Server Routing + +package main + +import "github.com/bmizerany/pat" +import "net/http" +import "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 +// todo: defaults +// todo: fallthroughs diff --git a/066-http-server-routing/http-server-routing.sh b/066-http-server-routing/http-server-routing.sh new file mode 100644 index 0000000..f61b62a --- /dev/null +++ b/066-http-server-routing/http-server-routing.sh @@ -0,0 +1,4 @@ +$ go get github.com/bmizerany/pat +$ go run xx-http-server-routing.go + +$ curl -i http://127.0.0.1:5000/hello/gopher diff --git a/067-http-server-static-dynamic/067-http-server-static-dynamic.go b/067-http-server-static-dynamic/http-server-static-dynamic.go similarity index 60% rename from 067-http-server-static-dynamic/067-http-server-static-dynamic.go rename to 067-http-server-static-dynamic/http-server-static-dynamic.go index 7cb5cba..0329b34 100644 --- a/067-http-server-static-dynamic/067-http-server-static-dynamic.go +++ b/067-http-server-static-dynamic/http-server-static-dynamic.go @@ -1,3 +1,5 @@ +// ## HTTP Server Static Dynamic + package main import "net/http" @@ -15,15 +17,6 @@ func main() { http.ListenAndServe(":5000", nil) } -// == running -// $ cd src -// $ go run xx-http-server-static-dynamic.go -// -// $ curl http://127.0.0.1:5000/hello -// $ curl http://127.0.0.1:5000/static -// $ curl http://127.0.0.1:5000/static/01-hello.go - -// == todo -// try to get dynamic at root -// try to get static at root -// favicon +// todo: try to get dynamic at root +// todo: try to get static at root +// todo: favicon diff --git a/067-http-server-static-dynamic/http-server-static-dynamic.sh b/067-http-server-static-dynamic/http-server-static-dynamic.sh new file mode 100644 index 0000000..cf1d030 --- /dev/null +++ b/067-http-server-static-dynamic/http-server-static-dynamic.sh @@ -0,0 +1,6 @@ +$ cd src +$ go run xx-http-server-static-dynamic.go + +$ curl http://127.0.0.1:5000/hello +$ curl http://127.0.0.1:5000/static +$ curl http://127.0.0.1:5000/static/01-hello.go diff --git a/068-http-server-static-select/068-http-server-static-select.go b/068-http-server-static-select/http-server-static-select.go similarity index 65% rename from 068-http-server-static-select/068-http-server-static-select.go rename to 068-http-server-static-select/http-server-static-select.go index c1219b1..78e9483 100644 --- a/068-http-server-static-select/068-http-server-static-select.go +++ b/068-http-server-static-select/http-server-static-select.go @@ -1,6 +1,10 @@ +// ## HTTP Server Static Select + package main -import ("net/http"; "fmt"; "code.google.com/p/gorilla/mux") +import "code.google.com/p/gorilla/mux" +import "net/http" +import "fmt" func hello(res http.ResponseWriter, req *http.Request) { res.Header().Set("Content-Type", "text/plain") @@ -24,12 +28,3 @@ func main() { r.HandleFunc("/{path:.*}", notFound) http.ListenAndServe(":5000", r) } - -// == running -// $ go get code.google.com/p/gorilla/mux -// $ go run xx-http-server-static-select.go -// -// $ curl -i http://127.0.0.1:5000/ -// $ curl -i http://127.0.0.1:5000/favicon.ico -// $ curl -i http://127.0.0.1:5000/wat -// $ curl -i http://127.0.0.1:5000/wat/wat diff --git a/068-http-server-static-select/http-server-static-select.sh b/068-http-server-static-select/http-server-static-select.sh new file mode 100644 index 0000000..5742eff --- /dev/null +++ b/068-http-server-static-select/http-server-static-select.sh @@ -0,0 +1,7 @@ +$ go get code.google.com/p/gorilla/mux +$ go run xx-http-server-static-select.go + +$ curl -i http://127.0.0.1:5000/ +$ curl -i http://127.0.0.1:5000/favicon.ico +$ curl -i http://127.0.0.1:5000/wat +$ curl -i http://127.0.0.1:5000/wat/wat