background

package module
v0.0.0-...-4badc5a Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

README

Background Processing

This directory contains an example of doing background processing with App Engine, Cloud Pub/Sub, Cloud Functions, and Firestore.

Deploy commands:

$ GO111MODULE=on gcloud app deploy
$ gcloud functions deploy --runtime=go111 --trigger-topic=translate Translate --set-env-vars GOOGLE_CLOUD_PROJECT=my-project

Documentation

Overview

Package background contains a Cloud Function to translate text. The function listens to Pub/Sub, does the translations, and stores the result in Firestore.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Translate

func Translate(ctx context.Context, m PubSubMessage) error

Translate translates the given message and stores the result in Firestore.

Types

type PubSubMessage

type PubSubMessage struct {
	Data []byte `json:"data"`
}

PubSubMessage is the payload of a Pub/Sub event. See https://cloud.google.com/functions/docs/calling/pubsub.

type Translation

type Translation struct {
	Original         string `json:"original"`
	Translated       string `json:"translated"`
	OriginalLanguage string `json:"original_language"`
	Language         string `json:"language"`
}

A Translation contains the original and translated text.

Directories

Path Synopsis
Command index is an HTTP app that displays all previous translations (stored in Firestore) and has a form to request new translations.
Command index is an HTTP app that displays all previous translations (stored in Firestore) and has a form to request new translations.

Jump to

Keyboard shortcuts

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