gofmt wat u know about it

This commit is contained in:
Mark McGranaghan
2012-09-23 18:31:33 -07:00
parent f93bdba75c
commit 89f95f2ac5
66 changed files with 729 additions and 678 deletions

View File

@@ -7,32 +7,32 @@ import "time"
import "fmt"
func runLogging(logs chan string) {
for log := range logs {
fmt.Println(log)
}
for log := range logs {
fmt.Println(log)
}
}
func wrapLogging(f http.HandlerFunc) http.HandlerFunc {
logs := make(chan string, 10000)
go runLogging(logs)
return func(res http.ResponseWriter, req *http.Request) {
start := time.Now()
f(res, req)
method := req.Method
path := req.URL.Path
elapsed := float64(time.Since(start)) / 1000000.0
logs <- fmt.Sprintf("method=%s path=%s elapsed=%f", method, path, elapsed)
}
logs := make(chan string, 10000)
go runLogging(logs)
return func(res http.ResponseWriter, req *http.Request) {
start := time.Now()
f(res, req)
method := req.Method
path := req.URL.Path
elapsed := float64(time.Since(start)) / 1000000.0
logs <- fmt.Sprintf("method=%s path=%s elapsed=%f", method, path, elapsed)
}
}
func hello(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "text/plain")
time.Sleep(time.Millisecond * 50)
fmt.Fprintln(res, "Hello logged world")
time.Sleep(time.Millisecond * 50)
fmt.Fprintln(res, "Hello logged world")
}
func main() {
handler := wrapLogging(hello)
handler := wrapLogging(hello)
http.HandleFunc("/", handler)
http.ListenAndServe(":5000", nil)
}