从切片中删除特定元素

I got this code:

type TimeSlot struct {
    ID int64 `json:"id" sql:"auto_increment"`
}

type Reserve struct {
    ID int64 `json:"id" sql:"auto_increment"`
    TimeSlot TimeSlot `gorm:"foreignkey:time_slot_id;association_autoupdate:false" json:"-"`
    TimeSlotID int64 `json:"time_slot_id"`
}

func GetFreeTimeSlotList (w http.ResponseWriter, r *http.Request) {
    var TimeSlotList models.TimeSlot
    List, err := models.TimeSlotStore.GetArray(&TimeSlotList)
    if err != nil {
        fmt.Fprintf(w, "Error GetArray of TimeSlots", err)
        w.Write([]byte(err.Error()))
        return
    }

    BookingReserveList, err := models.ReserveStore.GetArray(&models.Reserve{})
    if err != nil {
        fmt.Fprintf(w, "Error Getting booking Array!", err)
        fmt.Println("Error Getting booking Array!")
        return
    }

    *BookingReserveList = append(*BookingReserveList)
    for _, v := range *BookingReserveList {
        if v.TimeSlotID == TimeSlotList.ID {

        }
    }

    w.Header().Set("Content-Type", "application/json")
    err = json.NewEncoder(w).Encode(List)
    if err != nil {
        fmt.Fprintf(w, "Error encoding JSON", err)
        w.Write([]byte(err.Error()))
        return
    }

}


Reserve can be created only on the basis of TimeSlotID. Im' writing a method to output all unused slots. But I'm stuck at this point:

for _, v := range *BookingReserveList {
        if v.TimeSlotID == TimeSlotList.ID {

How can I subtract the elements from base slice and display the result?

Assuming you want all elements of Bookingreservelist which do not match a time slot, just create another empty list and append all elements you want, then return that. So something like:

var list []*List
for _, v := range *BookingReserveList {
    if v.TimeSlotID != TimeSlotList.ID {
        list = append(list,v)