Skip to content

Instantly share code, notes, and snippets.

@andriykohut
Created August 21, 2018 13:40
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 andriykohut/9ceb1080806e5445964ab7dcd15146c8 to your computer and use it in GitHub Desktop.
Save andriykohut/9ceb1080806e5445964ab7dcd15146c8 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func blah(data []map[string]interface{}) map[string]string {
result := make(map[string]string)
for _, item := range data {
tagTypeName := item["tag_type_name"].(string)
tagName := item["tag_name"].(string)
if tagTypeName == "profanity_status" {
result["profanity_status"] = tagName
} else if tagTypeName == "brand_unsafe" {
result[tagName] = item["accuracy"].(string)
}
}
return result
}
func main() {
data := []map[string]interface{}{
map[string]interface{}{"tag_type_name": "profanity_status", "tag_name": "profane"},
map[string]interface{}{"tag_type_name": "brand_unsafe", "tag_name": "profane", "accuracy": "42"},
}
for k, v := range blah(data) {
fmt.Printf("%s: %s\n", k, v)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment