如何使用String扩展session.Value

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

I thought that you should get original equipment value from the session, combine the equipment ID that user clicks on and save into session for the next request.

I update your code as following:

// ...
equipment, _ := model.GetEquipmentByID(r.FormValue("id"))
session, _ := store.Get(r, "cookie-name")

equipmentIdsStr := strconv.Itoa(equipment.ID)

if original, exist := session.Values["EquipmentIDs"]; exist {
    equipmentIdsStr = fmt.Sprintf("%v,%v", original, equipmentIdsStr)
}

session.Values["EquipmentIDs"] = equipmentIdsStr

//You have to save your updated session value
session.Save(r, w)
// ...

Hope this help.