Skip to content

Instantly share code, notes, and snippets.

@athom
Created July 27, 2012 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save athom/3186277 to your computer and use it in GitHub Desktop.
Save athom/3186277 to your computer and use it in GitHub Desktop.
an example of pat usage
package main
import (
"github.com/bmizerany/pat"
"io"
"log"
"net/http"
)
// hello world, the web server
func HelloServer(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, "hello, "+req.URL.Query().Get(":name")+"!\n")
}
// I want a route changable after host
func HelloRoot(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, "root: "+req.URL.Query().Get(":name")+"!\n")
}
func main() {
m := pat.New()
m.Get("/hello/:name", http.HandlerFunc(HelloServer))
m.Get("/:name/", http.HandlerFunc(HelloRoot))
// Register this pat with the default serve mux so that other packages
// may also be exported. (i.e. /debug/pprof/*)
http.Handle("/", m)
err := http.ListenAndServe(":12345", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
@JulesWang
Copy link

有啥用否?

@athom
Copy link
Author

athom commented Jul 29, 2012

给人家提issue的..

@athom
Copy link
Author

athom commented Jul 29, 2012

@kight
被否决了..
这是go里面的一个土鳖的router

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment