Created
June 2, 2014 03:09
-
-
Save alterakey/480eea848533a48f7fa7 to your computer and use it in GitHub Desktop.
Counting request in Go
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 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