Git Product home page Git Product logo

translation-api's Introduction

Translation gRPC API

Translate text with Amazon Translate and Google Translation.

License-MIT 


Table of Contents

Features

  • Translate text with Google Translation API and Amazon Translate API.

Setup

Create AWS and GCP account

This API uses AWS IAM and GCP service account to use each translation API.

For instructions on how to create an AWS account, see Creating an IAM user in your AWS account .

For a GCP account, see Creating and managing service accounts.

Prepare a TLS certificate

Create a server key file and TLS certificate if an API uses TLS.

e.g., Self-signed certificate

$ cd manifest/api/secret
$ openssl genrsa -aes256 -passout pass:gsahdg -out server.pass.key 4096
$ openssl rsa -passin pass:gsahdg -in server.pass.key -out server.key
$ rm server.pass.key
$ openssl req -new -key server.key -out server.csr
...
$ openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt

Ref. Generate private key and certificate signing request

Set environment variables

Need Several environment variables.

For details, see .env.example.

Deployment

Several examples are here.

Development

Tech stacks

  • Golang
  • gRPC
  • Kubernetes

Requirements

  • Golang: 1.14.4 darwin/amd64
  • Docker: 20.10.2
  • AWS IAM credentials, which can use Amazon Translate.
  • Google service account, which can use Google Translation API.

We tested in the above environment.

Setup

  1. Install Golang by following Download and install.
  2. Run go mod vendor to get modules.

Helper command

make

Build

$ make build

go test

Run test with details: "-v" and "-cover"

$ make test

Format sources

Run "go fmt", "goimports", and "go lint".

$ make fmt

On local

$ ./scripts/local.sh
Usage:
  ./scripts/local.sh Command

Example.
  ./scripts/local.sh build

Command:
  run           Run envoy and gRPC server on local.
  run:go        Run gRPC server on local.
  run:envoy     Run envoy on local.
  down:envoy    Stop envoy on local.
  grpc          Generate gRPC codes.

Structure

Design

Design

Sources

.
|-- Makefile            <-- Defines make command targets
|-- README.layout.md    <-- golang-standards/project-layout README
|-- README.md           <-- This instruction file
|-- cmd
|   `-- api
|       |-- .env.local      <-- Environment variables on local
|       |-- .env.example    <-- Environment variables example
|       |-- api             <-- This API binary
|       `-- api.go          <-- main func
|
|-- deployments
|   |-- docker-image            <-- Working directory for a container image
|   |-- eks                     <-- EKS deployment examples
|   |-- gcp                     <-- GKE deployment examples
|   `-- local                   <-- Example running on local
|
|-- internal
|   |-- app                     <-- This api directory
|   |   |-- controller          <-- Controller layer
|   |   |   `-- translator      <-- gRPC handler
|   |   |       `-- ...
|   |   |-- driver              <-- Driver layer
|   |   |   |-- aws             <-- Codes related to handling AWS translate service
|   |   |   |   `-- ...
|   |   |   |-- config          <-- Concrete implementation of Config methods
|   |   |   |   `-- ...
|   |   |   |
|   |   |   |-- google          <-- Codes related to handling Google Translation API.
|   |   |   |   `-- ...
|   |   |   |-- grpcserver      <-- gRPC server
|   |   |   |   `-- ...
|   |   |   `-- log             <-- Concrete implementation of Logger methods
|   |   |       `-- ...
|   |   |-- grpc                <-- Auto generated gRPC codes
|   |   |   `-- translator
|   |   |       |-- translator.proto    <-- gRPC service definition
|   |   |       `-- ...
|   |   |-- initializer.go      <-- App initializer func
|   |   `-- util                <-- Codes shared throughout the app
|   |       |-- config          <-- Config
|   |       |   |-- config.go
|   |       |   `-- ...
|   |       |-- di              <-- DI
|   |       |   |-- container   <-- Concrete implementation of DI methods
|   |       |   |   |-- dev
|   |       |   |   `-- ...
|   |       |   |-- di.go
|   |       |   `-- ...
|   |       `-- log             <-- Logging
|   |           |-- log.go
|   |           `-- ...
|   `-- pkg             <-- Codes shared, which are not dependent on the app
|       `-- util        <-- Helper functions
|           |-- file.go
|           |-- http.go
|           |-- time.go
|           `-- type.go
|
`-- scripts             <-- Scripts for this app
    |-- buildimage.sh   <-- For building container image
    |-- local.sh        <-- For local running
    |-- makefile.sh     <-- For Makefile
    `-- mock.pl         <-- To generate go mock file in the same directory

Get in touch

Contributing

Issues and reviews are welcome. Don't hesitate to create issues and PR.

License

© 2021 takakd

translation-api's People

Contributors

takakd avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.