dictionary

package module
v0.0.0-...-62517a1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2018 License: MIT Imports: 6 Imported by: 2

README

Build Status GoDoc Go Report Card Coverage Status

go-yandex-dictionary

Go Yandex Dictionary API wrapper

Usage:

package main

import (
  "fmt"
  "github.com/dafanasev/go-yandex-dictionary"
)

func main() {
  dict := dictionary.New("YOUR_API_KEY")

  langs, err := dict.GetLangs()

  if err != nil {
    fmt.Println(err)
  } else {
    fmt.Println(langs)
  }

  definition, err := dict.Lookup(&dictionary.Params{Lang: "en-ru", Text: "Dog"})

  if err != nil {
    fmt.Println(err)
  } else {
    fmt.Println(definition.Def[0].Text)
  }
}

Documentation

Overview

Package dictionary is the Yandex.Dictionary API client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Def

type Def struct {
	Text string
	Pos  string
	Ts   string
	Tr   []Tr
}

Def is the single definition

type Dictionary

type Dictionary struct {
	// contains filtered or unexported fields
}

Dictionary holds api key and ui lang

func New

func New(apiKey string) *Dictionary

New returns dictionary instance with english ui

func NewUsingLang

func NewUsingLang(apiKey string, ui string) *Dictionary

NewUsingLang returns dictionary instance with specified ui

func (*Dictionary) GetLangs

func (d *Dictionary) GetLangs() ([]string, error)

GetLangs returns list of supported languages

func (*Dictionary) Lookup

func (d *Dictionary) Lookup(params *Params) (*Entry, error)

Lookup returns results of api request wrapped in Entry structs

type Entry

type Entry struct {
	Code    int
	Message string
	Def     []Def
}

Entry is the root api response struct

type Ex

type Ex struct {
	Text string
	Tr   []Text
}

Ex is the examples array

type Params

type Params struct {
	Lang      string
	Text      string
	Family    bool
	Morpho    bool
	PosFilter bool
}

Params for api request

type Text

type Text struct {
	Text string
}

Text encapsulates string explaining the entity (definition, translation, example)

type Tr

type Tr struct {
	Text string
	Pos  string
	Ts   string
	Syn  []Text
	Mean []Text
	Ex   []Ex
}

Tr is the single translation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL