Translate text with Amazon Translate and Google Translation.
- Translate text with Google Translation API and Amazon Translate API.
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.
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
Need Several environment variables.
For details, see .env.example.
Several examples are here.
- Golang
- gRPC
- Kubernetes
- 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.
- Install Golang by following Download and install.
- Run
go mod vendor
to get modules.
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
$ ./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.
- Directory structure refers to golang-standards/project-layout.
- API services a translation service with gRPC.
.
|-- 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
Issues and reviews are welcome. Don't hesitate to create issues and PR.
© 2021 takakd