Package cloud.google.com/go/billing/apiv1 (v1.21.0)

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

Package billing is an auto-generated package for theCloud Billing API.

Allows developers to manage billing for their Google Cloud Platformprojects programmatically.

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/billing/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:=billing.NewCloudBillingClient(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:=&billingpb.CreateBillingAccountRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/billing/apiv1/billingpb#CreateBillingAccountRequest.}resp,err:=c.CreateBillingAccount(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp

Use of Context

The ctx passed to NewCloudBillingClient 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.

BillingAccountIterator

typeBillingAccountIteratorstruct{// Response is the raw response for the current page.// It must be cast to the RPC response type.// Calling Next() or InternalFetch() updates this value.Responseinterface{}// InternalFetch is for use by the Google Cloud Libraries only.// It is not part of the stable interface of this package.//// InternalFetch returns results from a single call to the underlying RPC.// The number of results is no greater than pageSize.// If there are no more results, nextPageToken is empty and err is nil.InternalFetchfunc(pageSizeint,pageTokenstring)(results[]*billingpb.BillingAccount,nextPageTokenstring,errerror)// contains filtered or unexported fields}

BillingAccountIterator manages a stream of *billingpb.BillingAccount.

func (*BillingAccountIterator) All

func(it*BillingAccountIterator)All()iter.Seq2[*billingpb.BillingAccount,error]

All returns an iterator. If an error is returned by the iterator, theiterator will stop after that iteration.

func (*BillingAccountIterator) Next

Next returns the next result. Its second return value is iterator.Done if there are no moreresults. Once Next returns Done, all subsequent calls will return Done.

func (*BillingAccountIterator) PageInfo

func(it*BillingAccountIterator)PageInfo()*iterator.PageInfo

PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.

CloudBillingCallOptions

typeCloudBillingCallOptionsstruct{GetBillingAccount[]gax.CallOptionListBillingAccounts[]gax.CallOptionUpdateBillingAccount[]gax.CallOptionCreateBillingAccount[]gax.CallOptionListProjectBillingInfo[]gax.CallOptionGetProjectBillingInfo[]gax.CallOptionUpdateProjectBillingInfo[]gax.CallOptionGetIamPolicy[]gax.CallOptionSetIamPolicy[]gax.CallOptionTestIamPermissions[]gax.CallOptionMoveBillingAccount[]gax.CallOption}

CloudBillingCallOptions contains the retry settings for each method of CloudBillingClient.

CloudBillingClient

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

CloudBillingClient is a client for interacting with Cloud Billing API.Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.

Retrieves the Google Cloud Console billing accounts and associates them withprojects.

func NewCloudBillingClient

funcNewCloudBillingClient(ctxcontext.Context,opts...option.ClientOption)(*CloudBillingClient,error)

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

Retrieves the Google Cloud Console billing accounts and associates them withprojects.

Example

packagemainimport("context"billing"cloud.google.com/go/billing/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:=billing.NewCloudBillingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()// TODO: Use client._=c}

func NewCloudBillingRESTClient

funcNewCloudBillingRESTClient(ctxcontext.Context,opts...option.ClientOption)(*CloudBillingClient,error)

NewCloudBillingRESTClient creates a new cloud billing rest client.

Retrieves the Google Cloud Console billing accounts and associates them withprojects.

Example

packagemainimport("context"billing"cloud.google.com/go/billing/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:=billing.NewCloudBillingRESTClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()// TODO: Use client._=c}

func (*CloudBillingClient) Close

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

func (*CloudBillingClient) Connection (deprecated)

func(c*CloudBillingClient)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 (*CloudBillingClient) CreateBillingAccount

CreateBillingAccount this method creates billingsubaccounts (athttps://cloud.google.com/billing/docs/concepts#subaccounts).

Google Cloud resellers should use theChannel Services APIs,accounts.customers.create (athttps://cloud.google.com/channel/docs/reference/rest/v1/accounts.customers/create)andaccounts.customers.entitlements.create (athttps://cloud.google.com/channel/docs/reference/rest/v1/accounts.customers.entitlements/create).

When creating a subaccount, the current authenticated user must have thebilling.accounts.update IAM permission on the parent account, which istypically given to billing accountadministrators (athttps://cloud.google.com/billing/docs/how-to/billing-access).This method will return an error if the parent account has not beenprovisioned for subaccounts.

Example

packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"billingpb"cloud.google.com/go/billing/apiv1/billingpb")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:=billing.NewCloudBillingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&billingpb.CreateBillingAccountRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/billing/apiv1/billingpb#CreateBillingAccountRequest.}resp,err:=c.CreateBillingAccount(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}

func (*CloudBillingClient) GetBillingAccount

GetBillingAccount gets information about a billing account. The current authenticated usermust be a viewer of the billingaccount (athttps://cloud.google.com/billing/docs/how-to/billing-access).

Example

packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"billingpb"cloud.google.com/go/billing/apiv1/billingpb")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:=billing.NewCloudBillingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&billingpb.GetBillingAccountRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/billing/apiv1/billingpb#GetBillingAccountRequest.}resp,err:=c.GetBillingAccount(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}

func (*CloudBillingClient) GetIamPolicy

GetIamPolicy gets the access control policy for a billing account.The caller must have the billing.accounts.getIamPolicy permission on theaccount, which is often given to billing accountviewers (athttps://cloud.google.com/billing/docs/how-to/billing-access).

Example

packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"iampb"cloud.google.com/go/iam/apiv1/iampb")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:=billing.NewCloudBillingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&iampb.GetIamPolicyRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest.}resp,err:=c.GetIamPolicy(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}

func (*CloudBillingClient) GetProjectBillingInfo

GetProjectBillingInfo gets the billing information for a project. The current authenticated usermust have the resourcemanager.projects.get permission for the project,which can be granted by assigning the ProjectViewer (athttps://cloud.google.com/iam/docs/understanding-roles#predefined_roles)role.

Example

packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"billingpb"cloud.google.com/go/billing/apiv1/billingpb")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:=billing.NewCloudBillingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&billingpb.GetProjectBillingInfoRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/billing/apiv1/billingpb#GetProjectBillingInfoRequest.}resp,err:=c.GetProjectBillingInfo(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}

func (*CloudBillingClient) ListBillingAccounts

ListBillingAccounts lists the billing accounts that the current authenticated user haspermission toview (athttps://cloud.google.com/billing/docs/how-to/billing-access).

Examples

packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"billingpb"cloud.google.com/go/billing/apiv1/billingpb""google.golang.org/api/iterator")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:=billing.NewCloudBillingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&billingpb.ListBillingAccountsRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/billing/apiv1/billingpb#ListBillingAccountsRequest.}it:=c.ListBillingAccounts(ctx,req)for{resp,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp// If you need to access the underlying RPC response,// you can do so by casting the `Response` as below.// Otherwise, remove this line. Only populated after// first call to Next(). Not safe for concurrent access._=it.Response.(*billingpb.ListBillingAccountsResponse)}}
all
packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"billingpb"cloud.google.com/go/billing/apiv1/billingpb")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:=billing.NewCloudBillingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&billingpb.ListBillingAccountsRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/billing/apiv1/billingpb#ListBillingAccountsRequest.}forresp,err:=rangec.ListBillingAccounts(ctx,req).All(){iferr!=nil{// TODO: Handle error and break/return/continue. Iteration will stop after any error.}// TODO: Use resp._=resp}}

func (*CloudBillingClient) ListProjectBillingInfo

ListProjectBillingInfo lists the projects associated with a billing account. The currentauthenticated user must have the billing.resourceAssociations.list IAMpermission, which is often given to billing accountviewers (athttps://cloud.google.com/billing/docs/how-to/billing-access).

Examples

packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"billingpb"cloud.google.com/go/billing/apiv1/billingpb""google.golang.org/api/iterator")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:=billing.NewCloudBillingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&billingpb.ListProjectBillingInfoRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/billing/apiv1/billingpb#ListProjectBillingInfoRequest.}it:=c.ListProjectBillingInfo(ctx,req)for{resp,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp// If you need to access the underlying RPC response,// you can do so by casting the `Response` as below.// Otherwise, remove this line. Only populated after// first call to Next(). Not safe for concurrent access._=it.Response.(*billingpb.ListProjectBillingInfoResponse)}}
all
packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"billingpb"cloud.google.com/go/billing/apiv1/billingpb")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:=billing.NewCloudBillingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&billingpb.ListProjectBillingInfoRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/billing/apiv1/billingpb#ListProjectBillingInfoRequest.}forresp,err:=rangec.ListProjectBillingInfo(ctx,req).All(){iferr!=nil{// TODO: Handle error and break/return/continue. Iteration will stop after any error.}// TODO: Use resp._=resp}}

func (*CloudBillingClient) MoveBillingAccount

MoveBillingAccount changes which parent organization a billing account belongs to.

Example

packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"billingpb"cloud.google.com/go/billing/apiv1/billingpb")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:=billing.NewCloudBillingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&billingpb.MoveBillingAccountRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/billing/apiv1/billingpb#MoveBillingAccountRequest.}resp,err:=c.MoveBillingAccount(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}

func (*CloudBillingClient) SetIamPolicy

SetIamPolicy sets the access control policy for a billing account. Replaces any existingpolicy.The caller must have the billing.accounts.setIamPolicy permission on theaccount, which is often given to billing accountadministrators (athttps://cloud.google.com/billing/docs/how-to/billing-access).

Example

packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"iampb"cloud.google.com/go/iam/apiv1/iampb")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:=billing.NewCloudBillingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&iampb.SetIamPolicyRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest.}resp,err:=c.SetIamPolicy(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}

func (*CloudBillingClient) TestIamPermissions

TestIamPermissions tests the access control policy for a billing account. This method takesthe resource and a set of permissions as input and returns the subset ofthe input permissions that the caller is allowed for that resource.

Example

packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"iampb"cloud.google.com/go/iam/apiv1/iampb")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:=billing.NewCloudBillingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&iampb.TestIamPermissionsRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest.}resp,err:=c.TestIamPermissions(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}

func (*CloudBillingClient) UpdateBillingAccount

UpdateBillingAccount updates a billing account’s fields.Currently the only field that can be edited is display_name.The current authenticated user must have the billing.accounts.updateIAM permission, which is typically given to theadministrator (athttps://cloud.google.com/billing/docs/how-to/billing-access)of the billing account.

Example

packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"billingpb"cloud.google.com/go/billing/apiv1/billingpb")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:=billing.NewCloudBillingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&billingpb.UpdateBillingAccountRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/billing/apiv1/billingpb#UpdateBillingAccountRequest.}resp,err:=c.UpdateBillingAccount(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}

func (*CloudBillingClient) UpdateProjectBillingInfo

UpdateProjectBillingInfo sets or updates the billing account associated with a project. You specifythe new billing account by setting the billing_account_name in theProjectBillingInfo resource to the resource name of a billing account.Associating a project with an open billing account enables billing on theproject and allows charges for resource usage. If the project already had abilling account, this method changes the billing account used for resourceusage charges.

Note: Incurred charges that have not yet been reported in the transactionhistory of the Google Cloud Console might be billed to the new billingaccount, even if the charge occurred before the new billing account wasassigned to the project.

The current authenticated user must have ownership privileges for boththeproject (athttps://cloud.google.com/docs/permissions-overview#h.bgs0oxofvnoo) and the billingaccount (athttps://cloud.google.com/billing/docs/how-to/billing-access).

You can disable billing on the project by setting thebilling_account_name field to empty. This action disassociates thecurrent billing account from the project. Any billable activity of yourin-use services will stop, and your application could stop functioning asexpected. Any unbilled charges to date will be billed to the previouslyassociated account. The current authenticated user must be either an ownerof the project or an owner of the billing account for the project.

Note that associating a project with a closed billing account will havemuch the same effect as disabling billing on the project: any paidresources used by the project will be shut down. Thus, unless you wish todisable billing, you should always call this method with the name of anopen billing account.

Example

packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"billingpb"cloud.google.com/go/billing/apiv1/billingpb")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:=billing.NewCloudBillingClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&billingpb.UpdateProjectBillingInfoRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/billing/apiv1/billingpb#UpdateProjectBillingInfoRequest.}resp,err:=c.UpdateProjectBillingInfo(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}

CloudCatalogCallOptions

typeCloudCatalogCallOptionsstruct{ListServices[]gax.CallOptionListSkus[]gax.CallOption}

CloudCatalogCallOptions contains the retry settings for each method of CloudCatalogClient.

CloudCatalogClient

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

CloudCatalogClient is a client for interacting with Cloud Billing API.Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.

A catalog of Google Cloud Platform services and SKUs.Provides pricing information and metadata on Google Cloud Platform servicesand SKUs.

func NewCloudCatalogClient

funcNewCloudCatalogClient(ctxcontext.Context,opts...option.ClientOption)(*CloudCatalogClient,error)

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

A catalog of Google Cloud Platform services and SKUs.Provides pricing information and metadata on Google Cloud Platform servicesand SKUs.

Example

packagemainimport("context"billing"cloud.google.com/go/billing/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:=billing.NewCloudCatalogClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()// TODO: Use client._=c}

func NewCloudCatalogRESTClient

funcNewCloudCatalogRESTClient(ctxcontext.Context,opts...option.ClientOption)(*CloudCatalogClient,error)

NewCloudCatalogRESTClient creates a new cloud catalog rest client.

A catalog of Google Cloud Platform services and SKUs.Provides pricing information and metadata on Google Cloud Platform servicesand SKUs.

Example

packagemainimport("context"billing"cloud.google.com/go/billing/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:=billing.NewCloudCatalogRESTClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()// TODO: Use client._=c}

func (*CloudCatalogClient) Close

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

func (*CloudCatalogClient) Connection (deprecated)

func(c*CloudCatalogClient)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 (*CloudCatalogClient) ListServices

ListServices lists all public cloud services.

Examples

packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"billingpb"cloud.google.com/go/billing/apiv1/billingpb""google.golang.org/api/iterator")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:=billing.NewCloudCatalogClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&billingpb.ListServicesRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/billing/apiv1/billingpb#ListServicesRequest.}it:=c.ListServices(ctx,req)for{resp,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp// If you need to access the underlying RPC response,// you can do so by casting the `Response` as below.// Otherwise, remove this line. Only populated after// first call to Next(). Not safe for concurrent access._=it.Response.(*billingpb.ListServicesResponse)}}
all
packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"billingpb"cloud.google.com/go/billing/apiv1/billingpb")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:=billing.NewCloudCatalogClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&billingpb.ListServicesRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/billing/apiv1/billingpb#ListServicesRequest.}forresp,err:=rangec.ListServices(ctx,req).All(){iferr!=nil{// TODO: Handle error and break/return/continue. Iteration will stop after any error.}// TODO: Use resp._=resp}}

func (*CloudCatalogClient) ListSkus

ListSkus lists all publicly available SKUs for a given cloud service.

Examples

packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"billingpb"cloud.google.com/go/billing/apiv1/billingpb""google.golang.org/api/iterator")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:=billing.NewCloudCatalogClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&billingpb.ListSkusRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/billing/apiv1/billingpb#ListSkusRequest.}it:=c.ListSkus(ctx,req)for{resp,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp// If you need to access the underlying RPC response,// you can do so by casting the `Response` as below.// Otherwise, remove this line. Only populated after// first call to Next(). Not safe for concurrent access._=it.Response.(*billingpb.ListSkusResponse)}}
all
packagemainimport("context"billing"cloud.google.com/go/billing/apiv1"billingpb"cloud.google.com/go/billing/apiv1/billingpb")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:=billing.NewCloudCatalogClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&billingpb.ListSkusRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/billing/apiv1/billingpb#ListSkusRequest.}forresp,err:=rangec.ListSkus(ctx,req).All(){iferr!=nil{// TODO: Handle error and break/return/continue. Iteration will stop after any error.}// TODO: Use resp._=resp}}

ProjectBillingInfoIterator

typeProjectBillingInfoIteratorstruct{// Response is the raw response for the current page.// It must be cast to the RPC response type.// Calling Next() or InternalFetch() updates this value.Responseinterface{}// InternalFetch is for use by the Google Cloud Libraries only.// It is not part of the stable interface of this package.//// InternalFetch returns results from a single call to the underlying RPC.// The number of results is no greater than pageSize.// If there are no more results, nextPageToken is empty and err is nil.InternalFetchfunc(pageSizeint,pageTokenstring)(results[]*billingpb.ProjectBillingInfo,nextPageTokenstring,errerror)// contains filtered or unexported fields}

ProjectBillingInfoIterator manages a stream of *billingpb.ProjectBillingInfo.

func (*ProjectBillingInfoIterator) All

func(it*ProjectBillingInfoIterator)All()iter.Seq2[*billingpb.ProjectBillingInfo,error]

All returns an iterator. If an error is returned by the iterator, theiterator will stop after that iteration.

func (*ProjectBillingInfoIterator) Next

Next returns the next result. Its second return value is iterator.Done if there are no moreresults. Once Next returns Done, all subsequent calls will return Done.

func (*ProjectBillingInfoIterator) PageInfo

func(it*ProjectBillingInfoIterator)PageInfo()*iterator.PageInfo

PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.

ServiceIterator

typeServiceIteratorstruct{// Response is the raw response for the current page.// It must be cast to the RPC response type.// Calling Next() or InternalFetch() updates this value.Responseinterface{}// InternalFetch is for use by the Google Cloud Libraries only.// It is not part of the stable interface of this package.//// InternalFetch returns results from a single call to the underlying RPC.// The number of results is no greater than pageSize.// If there are no more results, nextPageToken is empty and err is nil.InternalFetchfunc(pageSizeint,pageTokenstring)(results[]*billingpb.Service,nextPageTokenstring,errerror)// contains filtered or unexported fields}

ServiceIterator manages a stream of *billingpb.Service.

func (*ServiceIterator) All

func(it*ServiceIterator)All()iter.Seq2[*billingpb.Service,error]

All returns an iterator. If an error is returned by the iterator, theiterator will stop after that iteration.

func (*ServiceIterator) Next

Next returns the next result. Its second return value is iterator.Done if there are no moreresults. Once Next returns Done, all subsequent calls will return Done.

func (*ServiceIterator) PageInfo

func(it*ServiceIterator)PageInfo()*iterator.PageInfo

PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.

SkuIterator

typeSkuIteratorstruct{// Response is the raw response for the current page.// It must be cast to the RPC response type.// Calling Next() or InternalFetch() updates this value.Responseinterface{}// InternalFetch is for use by the Google Cloud Libraries only.// It is not part of the stable interface of this package.//// InternalFetch returns results from a single call to the underlying RPC.// The number of results is no greater than pageSize.// If there are no more results, nextPageToken is empty and err is nil.InternalFetchfunc(pageSizeint,pageTokenstring)(results[]*billingpb.Sku,nextPageTokenstring,errerror)// contains filtered or unexported fields}

SkuIterator manages a stream of *billingpb.Sku.

func (*SkuIterator) All

func(it*SkuIterator)All()iter.Seq2[*billingpb.Sku,error]

All returns an iterator. If an error is returned by the iterator, theiterator will stop after that iteration.

func (*SkuIterator) Next

func(it*SkuIterator)Next()(*billingpb.Sku,error)

Next returns the next result. Its second return value is iterator.Done if there are no moreresults. Once Next returns Done, all subsequent calls will return Done.

func (*SkuIterator) PageInfo

func(it*SkuIterator)PageInfo()*iterator.PageInfo

PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.

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.