Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjyoungblood/3801c4e3ebd5af500c3de2089ddef148 to your computer and use it in GitHub Desktop.
Save bjyoungblood/3801c4e3ebd5af500c3de2089ddef148 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func checkMap(m map[interface{}]interface{}, listName, value string) bool {
_list, ok := m[listName]
if !ok {
return false
}
list, ok := _list.([]interface{})
if !ok {
return false
}
for _, listItem := range list {
if str, ok := listItem.(string); ok {
if str == value {
return true
}
}
}
return false
}
func main() {
sampleMap := map[interface{}]interface{}{
"some-string": []interface{}{"value1", "value2"},
}
fmt.Println(checkMap(sampleMap, "some-string", "value1")) // true
fmt.Println(checkMap(sampleMap, "some-string", "bogus")) // false
fmt.Println(checkMap(sampleMap, "bogus", "value1")) // false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment