I have some Go code that is returning a map of values but I only need some of the results. Is there a way I can test/filter the key of the map against a string array (or something similar) to give a simplified result rather than a bunch of if statements? All the samples I have looked up had fixed values to filter against.
A simple example is below, but rather than supplying the string I want to have a list of possible values so I can get a reduced list.
package main
import "fmt"
type colors struct {
animal string
COLOR []string
}
func main() {
// Map animal names to color strings.
colors := map[string]string{
"bird": "blue",
"snake": "green",
"cat": "black",
}
// Display string.
fmt.Println(colors)
}