controller

package
v0.0.0-...-19e3c1d Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLanguageList

func GetLanguageList(w http.ResponseWriter, r *http.Request)

GetLanguageList send a request to Lingvanex server and convert the response into google format and reply back to the client.

func ServeStaticFile

func ServeStaticFile(w http.ResponseWriter, r *http.Request)

func Translate

func Translate(w http.ResponseWriter, r *http.Request)

Translate converts a Google format translate request into a Lingvanex format one which will be send to the Lingvanex server, and write a Google format response back to the client.

func TranslateRouter

func TranslateRouter(ctx context.Context) (chi.Router, error)

TranslateRouter add routers for translate requests and translate script requests.

Types

type LnxEndpointConfiguration

type LnxEndpointConfiguration struct {
	// A list of endpoint URLs.
	Endpoints []string
	// A list of default endpoint weights.
	DefaultWeights []float64
	// A GoogleLanguageList containing source language descriptions and target language descriptions.
	LanguagePairList language.GoogleLanguageList
	// A nested map of endpoint weights for a language pair.
	// The first key represents the source language, the second key represents the target language, the
	// third key represents the endpoint URL and the value the corresponding weight for that endpoint.
	LanguagePairWeights map[string]map[string]map[string]float64
}

LnxEndpointConfiguration describes a configuration of lingvanex endpoints, their supported languages and weights.

var (
	LnxEndpoint *LnxEndpointConfiguration
	LnxAPIKey   = os.Getenv("LNX_API_KEY")
)

func NewLnxEndpointConfiguration

func NewLnxEndpointConfiguration(endpoints []string, weights []float64, languageLists []language.GoogleLanguageList) (*LnxEndpointConfiguration, error)

NewLnxEndpointConfiguration returns a new endpoint configuration based on a list of endpoints, weights and list of supported languages

func (*LnxEndpointConfiguration) GetEndpoint

func (c *LnxEndpointConfiguration) GetEndpoint(from, to string) string

GetEndpoint returns the endpoint which should be used based on the weights and languages supported.

Jump to

Keyboard shortcuts

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