upstream

package
v0.0.0-...-28742d7 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package upstream provides implementations for upstream translation services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Azure

type Azure struct {
	// ServiceKey is the key from the Azure dashboard
	ServiceKey string
}

Azure represents a translation service calling the Azure Cognitive Services Machine Translation Service.

func (Azure) Translate

func (b Azure) Translate(givenPhrase string, givenLang, targetLang language.Tag, out *chan Result)

Translate call Microsoft Cognitive Services to translate the given string

type CircuitBreaker

type CircuitBreaker struct {
	Breaker *circuit.Breaker
	Timeout time.Duration
	Handler Service
}

CircuitBreaker implements a wrapper for upstream handlers that uses a CircuitBreaker to short-circuit requests given a user-specified circuit breaker

func (*CircuitBreaker) Translate

func (b *CircuitBreaker) Translate(givenPhrase string, givenLang, targetLang language.Tag, out *chan Result)

type Google

type Google struct {
	// Personal Access Token, as granted by Google.
	Key string
	// contains filtered or unexported fields
}

Google is a upstream.Service implementation that uses Google Cloud Translation.

func (Google) Translate

func (p Google) Translate(givenPhrase string, givenLang, targetLang language.Tag, out *chan Result)

Translate translates the given text using the Google Cloud Translation API. The translation result is sent to channel out.

type Mock

type Mock struct {
	Failing bool
	Delay   time.Duration
}

Mock is an implementation used to test error handling behaviour.

func (Mock) Translate

func (p Mock) Translate(givenPhrase string, givenLang, targetLang language.Tag, out *chan Result)

Translate returns an error if Failing flag is set. Otherwise, simply returns the original string. If Delay is set to non-zero values, waits for the given time before responding.

type Result

type Result struct {
	Error            error
	GivenPhrase      string
	GivenLang        language.Tag
	TargetLang       language.Tag
	TranslatedPhrase string
}

Result represents the result of a translation call to a service.

type Service

type Service interface {
	Translate(givenPhrase string, givenLang, targetLang language.Tag, out *chan Result)
}

Service represents an external service that provides translations.

Jump to

Keyboard shortcuts

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