Skip to content

Instantly share code, notes, and snippets.

@chilts

chilts/gist:1144739

Created Aug 14, 2011
Embed
What would you like to do?
package main
import (
"strconv"
"http"
"io"
"log"
"memcache"
)
// global variables
var mc *memcache.Client;
func init() {
mc = memcache.New("127.0.0.1:11211")
}
func main() {
// set up our handlers
http.HandleFunc("/test1", test1)
http.HandleFunc("/test2", test2)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err.String())
}
}
func test1(w http.ResponseWriter, r *http.Request) {
foo, err := mc.Increment("foo", 1)
if err != nil {
io.WriteString(w, err.String());
return
}
io.WriteString(w, "bar = ");
io.WriteString(w, strconv.Uitoa64(bar));
}
func test2(w http.ResponseWriter, r *http.Request) {
foo, err := mc.Increment("foo", 1)
if err != nil {
io.WriteString(w, err.String());
return
}
io.WriteString(w, "bar = ");
io.WriteString(w, strconv.Uitoa64(bar));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment