I'm a golang noob, so I'm making my first toy app by setting up a seed project for a gorilla based web app. It's going well but the session code doesn't work as I expect it to, here is the full code, and here is just the relevant snippet:
func getMyCounter(w http.ResponseWriter, r *http.Request){
session, _ := sessionStore.Get(r, counterSession)
if session.IsNew {
session.Values[myCounter] = 0
}
val := session.Values[myCounter].(int)
log.Printf("getMyCounter %d", val)
m := make(map[string]int)
m["counter"] = val
js, _ := json.Marshal(m)
w.Header().Set("Content-Type", "application/json")
w.Write(js)
}
func incrementMyCounter(w http.ResponseWriter, r *http.Request){
log.Println("incrementMyCounter")
session, _ := sessionStore.Get(r, counterSession)
if session.IsNew {
session.Values[myCounter] = 0
}
val := session.Values[myCounter].(int)
session.Values[myCounter] = val + 1
getMyCounter(w, r)
}
my calls to getMyCounter and incrementMyCounter always return 0