gcloud

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: BSD-2-Clause Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gcloud holds what the Google Cloud speech services share: the credentials they authorize with, and the codes Cloud Text-to-Speech names its languages by.

Index

Constants

View Source
const Scope = "https://www.googleapis.com/auth/cloud-platform"

Scope is the OAuth scope the Cloud speech APIs are authorized under. An application building its own token source should request it.

Variables

View Source
var ErrNoCredentials = errors.New("google: no valid credentials provided")

ErrNoCredentials is returned when none of the ways to authorize was given.

Functions

func STTLanguage added in v1.2.0

func STTLanguage(l language.Language) string

STTLanguage names a language the way Speech-to-Text V2 does. A language the table does not list is passed on as its full code, and logged.

func TTSLanguage

func TTSLanguage(l language.Language) string

TTSLanguage names a language the way Cloud Text-to-Speech does. A language the table does not list is passed on as its full code, and logged.

Types

type Credentials

type Credentials struct {
	// JSON is a service-account key: the contents of the key file Google Cloud
	// issues.
	JSON []byte
	// Path is the path of a service-account key file, read when JSON is empty.
	Path string
	// TokenSource mints and refreshes the access token, used when neither key
	// is given. It is how an application authorizes with anything beyond a
	// service-account key: Application Default Credentials, workload identity,
	// an impersonated service account. jargo reads no environment, so
	// Application Default Credentials are opt-in this way:
	//
	//	creds, err := google.FindDefaultCredentials(ctx, speech.Scope) // x/oauth2/google
	//	... Credentials{TokenSource: creds.TokenSource}
	TokenSource oauth2.TokenSource
}

Credentials says how to authorize against Google Cloud. One field is needed. When more than one is set, JSON is used first, then Path, then TokenSource.

func (Credentials) Given

func (c Credentials) Given() bool

Given reports whether any way to authorize was set.

func (Credentials) ProjectID

func (c Credentials) ProjectID() (string, error)

ProjectID is the project_id a service-account key names, read without exchanging the key. It is "" for a token source, and for a key naming none.

func (Credentials) Resolve

func (c Credentials) Resolve(ctx context.Context) (Resolved, error)

Resolve turns the credentials into a token source scoped to Cloud. A key is accepted only as a service-account key: another kind of credentials file can make the client read files or call URLs it names, which a key handed over as configuration should never do. ctx is held by the token source for its refreshes, so it must outlive the client using it.

func (Credentials) Validate

func (c Credentials) Validate() error

Validate reports whether the credentials name a way to authorize.

type Resolved

type Resolved struct {
	// TokenSource mints the access tokens.
	TokenSource oauth2.TokenSource
	// ProjectID is the project a service-account key belongs to, or "" when
	// the credentials were a token source, which names none.
	ProjectID string
}

Resolved is a set of credentials turned into what a client authorizes with.

Jump to

Keyboard shortcuts

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