Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

Go

7 thoughts
last posted Feb. 5, 2015, 2:54 p.m.

4 earlier thoughts

0

A perfect example of how lovely Go can be:

http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var handler http.Handler
select {
case <-(func() <-chan struct{} {
ch := make(chan struct{})
go func() {
time.Sleep(6 * time.Second)
close(ch)
}()
return ch
})():
handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("hello world"))
})
case <-time.After(5 * time.Second):
handler = UserTemplateResponse(http.StatusGatewayTimeout, ci)
}
handler.ServeHTTP(w, r)
})
view raw gistfile1.go hosted with ❤ by GitHub

This code is from Gondor's router during spin (being ported from original Python so not complete yet.)

2 later thoughts