ideas, better logging
This commit is contained in:
parent
8e209cd6ab
commit
44ad627f6c
12
README
12
README
@ -1,8 +1,10 @@
|
|||||||
= next
|
= next
|
||||||
get web presence in good enough shape to point to from blog post
|
get web presence in good enough shape to point to from blog post
|
||||||
gbe-web
|
gbe-web
|
||||||
force https, canonical host, request logging
|
graceful shutdown
|
||||||
|
staging site, behind basic auth
|
||||||
basic design / brand
|
basic design / brand
|
||||||
|
favicon
|
||||||
google analytics
|
google analytics
|
||||||
sign up form
|
sign up form
|
||||||
log archival
|
log archival
|
||||||
@ -62,11 +64,17 @@ devcenter
|
|||||||
* http://code.google.com/p/go-wiki/wiki/BoundingResourceUse
|
* http://code.google.com/p/go-wiki/wiki/BoundingResourceUse
|
||||||
|
|
||||||
= topics
|
= topics
|
||||||
|
* websockets
|
||||||
|
* html web scraping hn
|
||||||
|
* protocol buffers
|
||||||
|
* gomax procs
|
||||||
* noblocking send and non-blocking receive
|
* noblocking send and non-blocking receive
|
||||||
* dropping sends if buffer full
|
* dropping sends if buffer full
|
||||||
* web app
|
* web app
|
||||||
|
* accessing header values and query params
|
||||||
|
* accessing post body
|
||||||
* serve static files http://code.google.com/p/go-wiki/wiki/HttpStaticFiles
|
* serve static files http://code.google.com/p/go-wiki/wiki/HttpStaticFiles
|
||||||
* simultaneios assignement
|
* simultaneous assignment
|
||||||
* mongo
|
* mongo
|
||||||
* time formatting
|
* time formatting
|
||||||
* typed json parse/unparse
|
* typed json parse/unparse
|
||||||
|
@ -15,3 +15,7 @@ func main() {
|
|||||||
os.Setenv("FOO", "bar")
|
os.Setenv("FOO", "bar")
|
||||||
fmt.Println(os.Getenv("FOO"))
|
fmt.Println(os.Getenv("FOO"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// == todo
|
||||||
|
// ensure pattern
|
||||||
|
// link to 12 factor
|
||||||
|
@ -16,6 +16,7 @@ func wrapCanonicalHost(f http.HandlerFunc, canonicalHost string) http.HandlerFun
|
|||||||
hostPort[0] = canonicalHost
|
hostPort[0] = canonicalHost
|
||||||
url := "http://" + strings.Join(hostPort, ":") + req.URL.String()
|
url := "http://" + strings.Join(hostPort, ":") + req.URL.String()
|
||||||
http.Redirect(res, req, url, 301)
|
http.Redirect(res, req, url, 301)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
f(res, req)
|
f(res, req)
|
||||||
}
|
}
|
||||||
|
@ -2,34 +2,33 @@ package main
|
|||||||
|
|
||||||
import ("net/http"; "fmt"; "time")
|
import ("net/http"; "fmt"; "time")
|
||||||
|
|
||||||
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")
|
|
||||||
}
|
|
||||||
|
|
||||||
func wrapLogging(f http.HandlerFunc, logs chan string) http.HandlerFunc {
|
|
||||||
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 runLogging(logs chan string) {
|
func runLogging(logs chan string) {
|
||||||
for log := range logs {
|
for log := range logs {
|
||||||
fmt.Println(log)
|
fmt.Println(log)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func wrapLogging(f http.HandlerFunc, logs chan string) http.HandlerFunc {
|
||||||
logs := make(chan string, 10000)
|
logs := make(chan string, 10000)
|
||||||
go runLogging(logs)
|
go runLogging(logs)
|
||||||
handler := wrapLogging(hello, 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")
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
handler := wrapLogging(hello)
|
||||||
http.HandleFunc("/", handler)
|
http.HandleFunc("/", handler)
|
||||||
http.ListenAndServe(":5000", nil)
|
http.ListenAndServe(":5000", nil)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user