Service Control API v1 - Package cloud.google.com/go/servicecontrol/apiv1 (v1.14.6)

Note: To get more information about this package, such as access to older versions, viewthis package on pkg.go.dev.

Package servicecontrol is an auto-generated package for theService Control API.

Provides admission control and telemetry reporting for services integratedwith Service Infrastructure.

General documentation

For information that is relevant for all client libraries please referencehttps://pkg.go.dev/cloud.google.com/go#pkg-overview. Some information on thispage includes:

Example usage

To get started with this package, create a client.

// go get cloud.google.com/go/servicecontrol/apiv1@latestctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=servicecontrol.NewQuotaControllerClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()

The client will use your default application credentials. Clients should be reused instead of created as needed.The methods of Client are safe for concurrent use by multiple goroutines.The returned client must be Closed when it is done being used.

Using the Client

The following is an example of making an API call with the newly created client, mentioned above.

req:=&servicecontrolpb.AllocateQuotaRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/servicecontrol/apiv1/servicecontrolpb#AllocateQuotaRequest.}resp,err:=c.AllocateQuota(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp

Use of Context

The ctx passed to NewQuotaControllerClient is used for authentication requests andfor creating the underlying connection, but is not used for subsequent calls.Individual methods on the client use the ctx given to them.

To close the open connection, use the Close() method.

Functions

func DefaultAuthScopes

funcDefaultAuthScopes()[]string

DefaultAuthScopes reports the default set of authentication scopes to use with this package.

QuotaControllerCallOptions

typeQuotaControllerCallOptionsstruct{AllocateQuota[]gax.CallOption}

QuotaControllerCallOptions contains the retry settings for each method of QuotaControllerClient.

QuotaControllerClient

typeQuotaControllerClientstruct{// The call options for this service.CallOptions*QuotaControllerCallOptions// contains filtered or unexported fields}

QuotaControllerClient is a client for interacting with Service Control API.Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.

Google Quota Control API (at /service-control/overview)

Allows clients to allocate and release quota against a managedservice (athttps://cloud.google.com/service-management/reference/rpc/google.api/servicemanagement.v1#google.api.servicemanagement.v1.ManagedService).

func NewQuotaControllerClient

funcNewQuotaControllerClient(ctxcontext.Context,opts...option.ClientOption)(*QuotaControllerClient,error)

NewQuotaControllerClient creates a new quota controller client based on gRPC.The returned client must be Closed when it is done being used to clean up its underlying connections.

Google Quota Control API (at /service-control/overview)

Allows clients to allocate and release quota against a managedservice (athttps://cloud.google.com/service-management/reference/rpc/google.api/servicemanagement.v1#google.api.servicemanagement.v1.ManagedService).

Example

packagemainimport("context"servicecontrol"cloud.google.com/go/servicecontrol/apiv1")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=servicecontrol.NewQuotaControllerClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()// TODO: Use client._=c}

func NewQuotaControllerRESTClient

funcNewQuotaControllerRESTClient(ctxcontext.Context,opts...option.ClientOption)(*QuotaControllerClient,error)

NewQuotaControllerRESTClient creates a new quota controller rest client.

Google Quota Control API (at /service-control/overview)

Allows clients to allocate and release quota against a managedservice (athttps://cloud.google.com/service-management/reference/rpc/google.api/servicemanagement.v1#google.api.servicemanagement.v1.ManagedService).

Example

packagemainimport("context"servicecontrol"cloud.google.com/go/servicecontrol/apiv1")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=servicecontrol.NewQuotaControllerRESTClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()// TODO: Use client._=c}

func (*QuotaControllerClient) AllocateQuota

AllocateQuota attempts to allocate quota for the specified consumer. It should be calledbefore the operation is executed.

This method requires the servicemanagement.services.quotapermission on the specified service. For more information, seeCloud IAM (athttps://cloud.google.com/iam).

NOTE: The client must fail-open on server errors INTERNAL,UNKNOWN, DEADLINE_EXCEEDED, and UNAVAILABLE. To ensure systemreliability, the server may inject these errors to prohibit any harddependency on the quota functionality.

Example

packagemainimport("context"servicecontrol"cloud.google.com/go/servicecontrol/apiv1"servicecontrolpb"cloud.google.com/go/servicecontrol/apiv1/servicecontrolpb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=servicecontrol.NewQuotaControllerClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&servicecontrolpb.AllocateQuotaRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/servicecontrol/apiv1/servicecontrolpb#AllocateQuotaRequest.}resp,err:=c.AllocateQuota(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}

func (*QuotaControllerClient) Close

Close closes the connection to the API service. The user should invoke this whenthe client is no longer required.

func (*QuotaControllerClient) Connection (deprecated)

func(c*QuotaControllerClient)Connection()*grpc.ClientConn

Connection returns a connection to the API service.

Deprecated: Connections are now pooled so this method does not alwaysreturn the same resource.

ServiceControllerCallOptions

typeServiceControllerCallOptionsstruct{Check[]gax.CallOptionReport[]gax.CallOption}

ServiceControllerCallOptions contains the retry settings for each method of ServiceControllerClient.

ServiceControllerClient

typeServiceControllerClientstruct{// The call options for this service.CallOptions*ServiceControllerCallOptions// contains filtered or unexported fields}

ServiceControllerClient is a client for interacting with Service Control API.Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.

Google Service Control API (at /service-control/overview)

Lets clients check and report operations against a managedservice (athttps://cloud.google.com/service-management/reference/rpc/google.api/servicemanagement.v1#google.api.servicemanagement.v1.ManagedService).

func NewServiceControllerClient

funcNewServiceControllerClient(ctxcontext.Context,opts...option.ClientOption)(*ServiceControllerClient,error)

NewServiceControllerClient creates a new service controller client based on gRPC.The returned client must be Closed when it is done being used to clean up its underlying connections.

Google Service Control API (at /service-control/overview)

Lets clients check and report operations against a managedservice (athttps://cloud.google.com/service-management/reference/rpc/google.api/servicemanagement.v1#google.api.servicemanagement.v1.ManagedService).

Example

packagemainimport("context"servicecontrol"cloud.google.com/go/servicecontrol/apiv1")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=servicecontrol.NewServiceControllerClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()// TODO: Use client._=c}

func NewServiceControllerRESTClient

funcNewServiceControllerRESTClient(ctxcontext.Context,opts...option.ClientOption)(*ServiceControllerClient,error)

NewServiceControllerRESTClient creates a new service controller rest client.

Google Service Control API (at /service-control/overview)

Lets clients check and report operations against a managedservice (athttps://cloud.google.com/service-management/reference/rpc/google.api/servicemanagement.v1#google.api.servicemanagement.v1.ManagedService).

Example

packagemainimport("context"servicecontrol"cloud.google.com/go/servicecontrol/apiv1")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=servicecontrol.NewServiceControllerRESTClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()// TODO: Use client._=c}

func (*ServiceControllerClient) Check

Check checks whether an operation on a service should be allowed to proceedbased on the configuration of the service and related policies. It must becalled before the operation is executed.

If feasible, the client should cache the check results and reuse them for60 seconds. In case of any server errors, the client should rely on thecached results for much longer time to avoid outage.WARNING: There is general 60s delay for the configuration and policypropagation, therefore callers MUST NOT depend on the Check method havingthe latest policy information.

NOTE: the CheckRequest hasthe size limit (wire-format byte size) of 1MB.

This method requires the servicemanagement.services.check permissionon the specified service. For more information, seeCloud IAM (athttps://cloud.google.com/iam).

Example

packagemainimport("context"servicecontrol"cloud.google.com/go/servicecontrol/apiv1"servicecontrolpb"cloud.google.com/go/servicecontrol/apiv1/servicecontrolpb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=servicecontrol.NewServiceControllerClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&servicecontrolpb.CheckRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/servicecontrol/apiv1/servicecontrolpb#CheckRequest.}resp,err:=c.Check(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}

func (*ServiceControllerClient) Close

Close closes the connection to the API service. The user should invoke this whenthe client is no longer required.

func (*ServiceControllerClient) Connection (deprecated)

func(c*ServiceControllerClient)Connection()*grpc.ClientConn

Connection returns a connection to the API service.

Deprecated: Connections are now pooled so this method does not alwaysreturn the same resource.

func (*ServiceControllerClient) Report

Report reports operation results to Google Service Control, such as logs andmetrics. It should be called after an operation is completed.

If feasible, the client should aggregate reporting data for up to 5seconds to reduce API traffic. Limiting aggregation to 5 seconds is toreduce data loss during client crashes. Clients should carefully choosethe aggregation time window to avoid data loss risk more than 0.01%for business and compliance reasons.

NOTE: the ReportRequest hasthe size limit (wire-format byte size) of 1MB.

This method requires the servicemanagement.services.report permissionon the specified service. For more information, seeGoogle Cloud IAM (athttps://cloud.google.com/iam).

Example

packagemainimport("context"servicecontrol"cloud.google.com/go/servicecontrol/apiv1"servicecontrolpb"cloud.google.com/go/servicecontrol/apiv1/servicecontrolpb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=servicecontrol.NewServiceControllerClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&servicecontrolpb.ReportRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/servicecontrol/apiv1/servicecontrolpb#ReportRequest.}resp,err:=c.Report(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-30 UTC.