Skip to content

Instantly share code, notes, and snippets.

@chilts
Created August 14, 2011 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chilts/1144739 to your computer and use it in GitHub Desktop.
Save chilts/1144739 to your computer and use it in GitHub Desktop.
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