routing
This commit is contained in:
19
src/xx-http-server-routing.go
Normal file
19
src/xx-http-server-routing.go
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user