Skip to content

Instantly share code, notes, and snippets.

@itang
Created June 14, 2012 04:38
Show Gist options
  • Save itang/2928022 to your computer and use it in GitHub Desktop.
Save itang/2928022 to your computer and use it in GitHub Desktop.
pat test
package main
import (
"io"
"net/http"
"github.com/bmizerany/pat"
"log"
"runtime"
"time"
)
// hello world, the web server
func HelloServer(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, "hello, "+req.URL.Query().Get(":name")+"!\n")
}
func main() {
log.Println(runtime.NumCPU())
m := pat.New()
m.Get("/hello/:name", http.HandlerFunc(HelloServer))
// Register this pat with the default serve mux so that other packages
// may also be exported. (i.e. /debug/pprof/*)
http.Handle("/", m)
c := make(chan bool)
go func(c chan bool) {
err := http.ListenAndServe(":8080", nil)
if err != nil {
c <- false
log.Println(time.Millisecond)
// time.Sleep(1000 * time.Millisecond )
log.Fatal("ListenAndServe: ", err)
}else{
c <- true
}
}(c)
log.Println("start at 8080")
if ret := <-c;ret {
log.Println("OK")
}else {
log.Println("Error")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment