internaloption

package
v0.171.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: BSD-3-Clause Imports: 3 Imported by: 2,481

Documentation

Overview

Package internaloption contains options used internally by Google client code.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowNonDefaultServiceAccount added in v0.55.0

func AllowNonDefaultServiceAccount(nd bool) option.ClientOption

AllowNonDefaultServiceAccount returns a ClientOption that overrides the default requirement for using the default service account for DirectPath.

It should only be used internally by generated clients. This is an EXPERIMENTAL API and may be changed or removed in the future.

func EnableDirectPath added in v0.35.0

func EnableDirectPath(dp bool) option.ClientOption

EnableDirectPath returns a ClientOption that overrides the default attempt to use DirectPath.

It should only be used internally by generated clients. This is an EXPERIMENTAL API and may be changed or removed in the future.

func EnableDirectPathXds added in v0.119.0

func EnableDirectPathXds() option.ClientOption

EnableDirectPathXds returns a ClientOption that overrides the default DirectPath type. It is only valid when DirectPath is enabled.

It should only be used internally by generated clients. This is an EXPERIMENTAL API and may be changed or removed in the future.

func EnableJwtWithScope added in v0.49.0

func EnableJwtWithScope() option.ClientOption

EnableJwtWithScope returns a ClientOption that specifies if scope can be used with self-signed JWT.

EnableJwtWithScope is ignored when option.WithUniverseDomain is set to a value other than the Google Default Universe (GDU) of "googleapis.com". For non-GDU domains, token exchange is impossible and services must support self-signed JWTs with scopes.

func EnableNewAuthLibrary added in v0.142.0

func EnableNewAuthLibrary() option.ClientOption

EnableNewAuthLibrary returns a ClientOption that specifies if libraries in this module to delegate auth to our new library. This option will be removed in the future once all clients have been moved to the new auth layer.

func SkipDialSettingsValidation added in v0.30.0

func SkipDialSettingsValidation() option.ClientOption

SkipDialSettingsValidation bypasses validation on ClientOptions.

It should only be used internally.

func WithCredentials added in v0.56.0

func WithCredentials(creds *google.Credentials) option.ClientOption

WithCredentials returns a client option to specify credentials which will be used to authenticate API calls. This credential takes precedence over all other credential options.

func WithDefaultAudience added in v0.36.0

func WithDefaultAudience(audience string) option.ClientOption

WithDefaultAudience returns a ClientOption that specifies a default audience to be used as the audience field ("aud") for the JWT token authentication.

It should only be used internally by generated clients.

func WithDefaultEndpoint deprecated

func WithDefaultEndpoint(url string) option.ClientOption

WithDefaultEndpoint is an option that indicates the default endpoint.

It should only be used internally by generated clients.

This is similar to WithEndpoint, but allows us to determine whether the user has overridden the default endpoint.

Deprecated: WithDefaultEndpoint does not support setting the universe domain. Use WithDefaultEndpointTemplate and WithDefaultUniverseDomain to compose the default endpoint instead.

func WithDefaultEndpointTemplate added in v0.155.0

func WithDefaultEndpointTemplate(url string) option.ClientOption

WithDefaultEndpointTemplate provides a template for creating the endpoint using a universe domain. See also WithDefaultUniverseDomain and option.WithUniverseDomain. The placeholder UNIVERSE_DOMAIN should be used instead of a concrete universe domain such as "googleapis.com".

Example: WithDefaultEndpointTemplate("https://logging.UNIVERSE_DOMAIN/")

It should only be used internally by generated clients.

func WithDefaultMTLSEndpoint added in v0.29.0

func WithDefaultMTLSEndpoint(url string) option.ClientOption

WithDefaultMTLSEndpoint is an option that indicates the default mTLS endpoint.

It should only be used internally by generated clients.

func WithDefaultScopes added in v0.36.0

func WithDefaultScopes(scope ...string) option.ClientOption

WithDefaultScopes returns a ClientOption that overrides the default OAuth2 scopes to be used for a service.

It should only be used internally by generated clients.

func WithDefaultUniverseDomain added in v0.153.0

func WithDefaultUniverseDomain(ud string) option.ClientOption

WithDefaultUniverseDomain returns a ClientOption that sets the default universe domain.

It should only be used internally by generated clients.

This is similar to the public WithUniverse, but allows us to determine whether the user has overridden the default universe.

Types

type EmbeddableAdapter added in v0.106.0

type EmbeddableAdapter struct{}

EmbeddableAdapter is a no-op option.ClientOption that allow libraries to create their own client options by embedding this type into their own client-specific option wrapper. See example for usage.

Example
package main

import (
	"context"
	"fmt"

	"google.golang.org/api/option"
	"google.golang.org/api/option/internaloption"
)

type config struct {
	i int
}

type clientSpecificOption interface {
	option.ClientOption
	ApplyOpt(*config)
}

func WithFavoriteNumber(i int) option.ClientOption {
	return &withFavoriteNumber{i: i}
}

type withFavoriteNumber struct {
	internaloption.EmbeddableAdapter
	i int
}

func (w *withFavoriteNumber) ApplyOpt(c *config) {
	c.i = w.i
}

type Foo struct {
	i int
}

func NewFoo(ctx context.Context, opts ...option.ClientOption) (*Foo, error) {
	var conf config
	for _, opt := range opts {
		if fooOpt, ok := opt.(clientSpecificOption); ok {
			fooOpt.ApplyOpt(&conf)
		}
	}
	// Pass options to internals for dialing. All client-specific options will
	// be no-ops.
	return &Foo{i: conf.i}, nil
}

func (f *Foo) Number() int { return f.i }

func main() {
	f, err := NewFoo(context.Background(), WithFavoriteNumber(42))
	if err != nil {
		// TODO: handle error
	}
	fmt.Println(f.Number())
}
Output:

42

func (*EmbeddableAdapter) Apply added in v0.106.0

Jump to

Keyboard shortcuts

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