diff options
Diffstat (limited to 'lookup_response.go')
| -rw-r--r-- | lookup_response.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lookup_response.go b/lookup_response.go index 4a6ed07..346bcd8 100644 --- a/lookup_response.go +++ b/lookup_response.go @@ -3,5 +3,49 @@ package kbbi +import ( + "fmt" + "io" +) + // LookupResponse contains mapping of word and its definition. type LookupResponse map[string]*Word + +// Write print each word and its lookup information to the out. +func (res LookupResponse) Write(out io.Writer) { + var ( + word string + wordDef *Word + err error + ) + for word, wordDef = range res { + err = wordDef.Err() + if err != nil { + fmt.Fprintf(out, "!!! %s: %s\n", word, err) + fmt.Fprintln(out) + continue + } + + fmt.Fprintln(out, `===`, word) + fmt.Fprintln(out) + if len(wordDef.Message) != 0 { + fmt.Fprintln(out, `?`, wordDef.Message) + fmt.Fprintln(out) + continue + } + if len(wordDef.Root) > 0 { + fmt.Fprintf(out, "Kata dasar: %s\n", wordDef.Root) + } + for x, def := range wordDef.Definition { + fmt.Fprintf(out, "Definisi #%d: %s\n", x+1, def.Value) + + for y, nomina := range def.Classes { + fmt.Fprintf(out, " Kelas #%d: %s\n", y+1, nomina) + } + for z, contoh := range def.Examples { + fmt.Fprintf(out, " Contoh #%d: %s\n", z+1, contoh) + } + fmt.Fprintln(out) + } + } +} |
