Golang:与“添加”相反,用于删除数据

Here's the how I append data to struct:

user.Things = append(user.Things, item.Id)

Now, how can I remove item.id from user.Things? Seems like there's no method like delete, remove, or similar.

For example, this didn't work:

user.Things = append(user.Things[:item.id], user.Things[:item.id + 1:])

The wiki page Slice tricks gives a good overview about operations on slices.

There is also a few ways to delete an elements a slice: cutting, deleting or deleting without preserving order.

In your case, it seems you just had a typo (an extra colon):

user.Things = append(user.Things[:item.id], user.Things[item.id + 1:])