Created
April 21, 2016 22:11
-
-
Save bjyoungblood/3801c4e3ebd5af500c3de2089ddef148 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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