Correct parsing for usages
This commit is contained in:
parent
0c2bba4be4
commit
9d1ef2b462
18
main.go
18
main.go
|
@ -90,6 +90,7 @@ func parseUsages(json map[string]interface{}, language string) (usages []Usage)
|
||||||
usage.PartOfSpeech = v["partOfSpeech"].(string)
|
usage.PartOfSpeech = v["partOfSpeech"].(string)
|
||||||
usage.Lang = v["language"].(string)
|
usage.Lang = v["language"].(string)
|
||||||
usage.Definitions = parseDefinitions(v["definitions"].([]interface{}))
|
usage.Definitions = parseDefinitions(v["definitions"].([]interface{}))
|
||||||
|
usages = append(usages, usage)
|
||||||
default:
|
default:
|
||||||
fmt.Println("Some other type", v)
|
fmt.Println("Some other type", v)
|
||||||
}
|
}
|
||||||
|
@ -97,13 +98,12 @@ func parseUsages(json map[string]interface{}, language string) (usages []Usage)
|
||||||
default:
|
default:
|
||||||
fmt.Println(key, "is some other type")
|
fmt.Println(key, "is some other type")
|
||||||
}
|
}
|
||||||
usages = append(usages, usage)
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
langPtr := flag.String("l", "*", "2-letter code for the language you want to search, use \"*\" to include all language")
|
langPtr := flag.String("l", "en", "2-letter code for the language you want to search,\nuse \"*\" to include all language")
|
||||||
wordPtr := flag.String("w", "default", "The word you want to look up")
|
wordPtr := flag.String("w", "default", "The word you want to look up")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
word := *wordPtr
|
word := *wordPtr
|
||||||
|
@ -135,17 +135,21 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
usages := parseUsages(parsedResponse, *langPtr)
|
usages := parseUsages(parsedResponse, *langPtr)
|
||||||
|
var currentLang string
|
||||||
for _, usage := range usages {
|
for _, usage := range usages {
|
||||||
|
if currentLang != usage.Lang {
|
||||||
fmt.Println(usage.Lang)
|
fmt.Println(usage.Lang)
|
||||||
fmt.Println("Part of Speech:", usage.PartOfSpeech)
|
currentLang = usage.Lang
|
||||||
fmt.Println("Definitions:")
|
}
|
||||||
|
fmt.Println("\tPart of Speech:", usage.PartOfSpeech)
|
||||||
|
fmt.Println("\tDefinitions:")
|
||||||
for i, definition := range usage.Definitions {
|
for i, definition := range usage.Definitions {
|
||||||
fmt.Print(i + 1, ". ")
|
fmt.Print("\t", i + 1, ". ")
|
||||||
fmt.Println(definition.Def)
|
fmt.Println(definition.Def)
|
||||||
if definition.Examples != nil {
|
if definition.Examples != nil {
|
||||||
fmt.Println("Examples")
|
fmt.Println("\t", "Examples")
|
||||||
for _, example := range definition.Examples {
|
for _, example := range definition.Examples {
|
||||||
fmt.Print("- ")
|
fmt.Print("\t", "- ")
|
||||||
fmt.Println(example)
|
fmt.Println(example)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue