deepl

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const TRANSLATE = "/translate"

Variables

View Source
var ErrMissingAuthKey = errors.New("missing DeepL authKey")

Functions

func HandleHTTPError

func HandleHTTPError(resp *http.Response) error

Types

type APIClient

type APIClient interface {
	Translate(context.Context, string, string, string) (*Translate, error)
}

type Client

type Client struct {
	BaseURL    *url.URL
	HTTPClient *http.Client
	AuthKey    string
}

func NewClient

func NewClient(rawBaseURL, authKey string) (*Client, error)

func (*Client) Translate

func (c *Client) Translate(ctx context.Context, text, sourceLang, targetLang string) (*Translate, error)

type HTTPError

type HTTPError struct {
	StatusCode int
	RequestURL string
	Message    string
}

func (HTTPError) Error

func (err HTTPError) Error() string

type Translate

type Translate struct {
	Translations []Translation `json:"translations"`
}

func (*Translate) TranslateText

func (t *Translate) TranslateText() string

type Translation

type Translation struct {
	DetectedSourceLanguage string `json:"detected_source_language"`
	Text                   string `json:"text"`
}

Directories

Path Synopsis
Package mock_deepl is a generated GoMock package.
Package mock_deepl is a generated GoMock package.

Jump to

Keyboard shortcuts

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