What is the best way to check whether a certain value is in a string slice? I would use a Set in other languages, but Go doesn\'t have one.
My best try is this so far:>
To replace sets you should use a map[string]struct{}
. This is efficient and considered idiomatic, the "values" take absolutely no space.
Initialize the set:
set := make(map[string]struct{})
Put an item :
set["item"]=struct{}{}
Check whether an item is present:
_, isPresent := set["item"]
Remove an item:
delete(set, "item")