updates
This commit is contained in:
parent
0de3674882
commit
360105bc64
@ -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
|
21
066-http-server-routing/http-server-routing.go
Normal file
21
066-http-server-routing/http-server-routing.go
Normal 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
|
4
066-http-server-routing/http-server-routing.sh
Normal file
4
066-http-server-routing/http-server-routing.sh
Normal 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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user