Created
August 14, 2011 09:34
-
-
Save chilts/1144739 to your computer and use it in GitHub Desktop.
This file contains 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 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