Created
June 14, 2012 04:38
-
-
Save itang/2928022 to your computer and use it in GitHub Desktop.
pat test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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