routing
This commit is contained in:
parent
df39e7f534
commit
62d61b1b86
1
README
1
README
@ -40,7 +40,6 @@ gobyexample.com signups
|
|||||||
|
|
||||||
= topics
|
= topics
|
||||||
* web app
|
* web app
|
||||||
* routing
|
|
||||||
* serve static files
|
* serve static files
|
||||||
* string formatting
|
* string formatting
|
||||||
* mongo
|
* mongo
|
||||||
|
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
|
Loading…
x
Reference in New Issue
Block a user