This commit is contained in:
Mark McGranaghan 2012-09-23 12:17:57 -07:00
parent 0de3674882
commit 360105bc64
7 changed files with 48 additions and 47 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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