Skip to content

Instantly share code, notes, and snippets.

@alterakey
Created June 2, 2014 03:09
Show Gist options
  • Save alterakey/480eea848533a48f7fa7 to your computer and use it in GitHub Desktop.
Save alterakey/480eea848533a48f7fa7 to your computer and use it in GitHub Desktop.
Counting request in Go
package hello
import (
"fmt"
"net/http"
)
func init() {
http.HandleFunc("/", handler)
}
var cnt uint32
func handler(w http.ResponseWriter, r *http.Request) {
if (r.URL.Path == "/") {
fmt.Fprintf(w, "counter: %d", cnt)
cnt = cnt + 1
} else {
http.NotFound(w, r)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment