You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

28 lines
568 B

  1. package main
  2. import (
  3. "io"
  4. "log"
  5. "net/http"
  6. "github.com/bmizerany/pat"
  7. )
  8. // hello world, the web server
  9. func HelloServer(w http.ResponseWriter, req *http.Request) {
  10. io.WriteString(w, "hello, "+req.URL.Query().Get(":name")+"!\n")
  11. }
  12. func main() {
  13. m := pat.New()
  14. m.Get("/hello/:name", http.HandlerFunc(HelloServer))
  15. // Register this pat with the default serve mux so that other packages
  16. // may also be exported. (i.e. /debug/pprof/*)
  17. http.Handle("/", m)
  18. err := http.ListenAndServe(":12345", nil)
  19. if err != nil {
  20. log.Fatal("ListenAndServe: ", err)
  21. }
  22. }