Skip to content

Instantly share code, notes, and snippets.

@Chever-John
Last active April 10, 2022 15:55
Show Gist options
  • Save Chever-John/534ad65c9b842ab4cc2bc1b69021af10 to your computer and use it in GitHub Desktop.
Save Chever-John/534ad65c9b842ab4cc2bc1b69021af10 to your computer and use it in GitHub Desktop.
Using map[...]bool to simulate a set in golang.
package main
import "fmt"
var validNames = map[string]bool{
"blue": true,
"yellow": true,
}
func main() {
if validNames["blue"] {
fmt.Println("blue is ok!")
}
if validNames["green"] {
fmt.Println("green is ok!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment