Iam using Gorilla/Sessions.
I got a template page, where the user can choose between different devices. If he uses one of the submit buttons under each device my controller function should add the id value to my existing session value.
func Cart(w http.ResponseWriter, r *http.Request) {
data := CartData{
Name: "Cart",
Equipment: model.GetEquipment(model.Db),
Pages: []Page{
{
Title: "Meine Geräte",
Active: false,
Link: "/my-equipment",
},
{
Title: "Equipment",
Active: false,
Link: "/equipment",
},
{
Title: "Logout",
Active: false,
Link: "/logout",
},
},
}
equipment,_ := model.GetEquipmentByID(r.FormValue("id"))
session, _ := store.Get(r, "cookie-name")
Strings := strconv.Itoa(equipment.ID)
fmt.Println(Strings)
StringsWithComma := Strings + ","
session.Values["EquipmentIDs"] = session.Values["EquipmentIDs"] + StringsWithComma // THIS CODE LINE DOES NOT WORK, I want to expand "EquipmentIDs" with the new ID
tmpl:= template.Must(template.ParseFiles("template/base_user.html", "template/cart.html"))
tmpl.ExecuteTemplate(w, "base", data)
}
}
Example: User is visiting my Device page. He uses the submit button with id=2 SessionValue["EquipmentIDs"] should be = "2" right now. After that the User is visiting the Device Page again an uses the submit button with id=6. Now the SessionValue should be = "2,6"
I am attached to the problem all day and can not get any further If you have Questions or want to see other parts of my code feel free to ask Thanks in advance