### WritePreviewRequest Examples (Files and Draft) Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/endpoints.md Examples demonstrating how to create a WritePreviewRequest. One example shows creating a preview from files, and the other shows creating it from an existing draft. ```go // From files req := &sdk.WritePreviewRequest{ Parent: "projects/my-project", Source: &sdk.WritePreviewRequest_Files{ Files: &sdk.Files{...}, }, PreviewSettings: &sdk.WritePreviewRequest_PreviewSettings{ Sandbox: true, }, } ``` ```go // From draft req := &sdk.WritePreviewRequest{ Parent: "projects/my-project", Source: &sdk.WritePreviewRequest_Draft{ Draft: &sdk.WritePreviewRequest_ContentFromDraft{}, }, PreviewSettings: &sdk.WritePreviewRequest_PreviewSettings{}, } ``` -------------------------------- ### Construct DebugInfo Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-rpc-errdetails.md Example of creating a `DebugInfo` object with sample stack trace entries and a detail message. ```go debugInfo := &errdetails.DebugInfo{ StackEntries: []string{ "goroutine 1 [running]", "main.myFunction()", " /path/to/file.go:42", }, Detail: "Assertion failed: x > 0", } ``` -------------------------------- ### Color Constructor Examples Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-common-types.md Demonstrates how to create Color objects for pure red with full opacity and a semi-transparent blue. ```go import "google.golang.org/genproto/googleapis/type/color" // Red color with full opacity red := &color.Color{ Red: 1.0, Green: 0.0, Blue: 0.0, Alpha: 1.0, } // Semi-transparent blue lightBlue := &color.Color{ Red: 0.0, Green: 0.5, Blue: 1.0, Alpha: 0.5, } ``` -------------------------------- ### Example Usage: Create Production Version Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-actions-sdk-v2.md Demonstrates how to construct a CreateVersionRequest for creating a production release channel version. ```go // Create production version req := &sdk.CreateVersionRequest{ Parent: "projects/my-project", ReleaseChannel: "actions.channels.Production", Files: &sdk.Files{ ConfigFiles: []*sdk.ConfigFile{...}, }, } ``` -------------------------------- ### Get Go Generated Proto Packages Source: https://github.com/googleapis/go-genproto/blob/main/README.md Use this command to fetch all generated Go proto packages from the repository. Ensure you have Go installed and configured. ```bash go get google.golang.org/genproto/... ``` -------------------------------- ### DateRange Constructor Example Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-common-types.md Shows how to instantiate a DateRange object for the year 2026. ```go import ( "google.golang.org/genproto/googleapis/type/date" "google.golang.org/genproto/googleapis/type/date_range" ) dateRange := &date_range.DateRange{ StartDate: &date.Date{Year: 2026, Month: 1, Day: 1}, EndDate: &date.Date{Year: 2026, Month: 12, Day: 31}, } ``` -------------------------------- ### Example DebugInfo Usage Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-rpc-errdetails.md Demonstrates constructing a `DebugInfo` object using dynamic data, such as extracted stack traces and formatted request details. ```go debugInfo := &errdetails.DebugInfo{ StackEntries: extractStackTrace(), Detail: fmt.Sprintf("Processing request ID: %s, user: %s", requestID, userID), } ``` -------------------------------- ### CreateVersionRequest Example Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/endpoints.md Example of constructing a CreateVersionRequest to create a new released version for the Actions SDK service. Specify the parent project and the release channel. ```go req := &sdk.CreateVersionRequest{ Parent: "projects/my-project", ReleaseChannel: "actions.channels.Production", Files: &sdk.Files{ ConfigFiles: []*sdk.ConfigFile{...}, }, } ``` -------------------------------- ### BundledQuery Constructor Example Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/firestore-bundle.md Illustrates how to create a new BundledQuery instance with specified parent, query type, and limit type. ```go bq := &BundledQuery{ Parent: "projects/my-project/databases/(default)", QueryType: &BundledQuery_StructuredQuery{ StructuredQuery: &v1.StructuredQuery{...}, }, LimitType: BundledQuery_FIRST, } ``` -------------------------------- ### BundledQuery Example Usage Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/firestore-bundle.md Provides a practical example of creating a `BundledQuery` for a collection, including setting the parent, a structured query with a collection ID and limit, and the limit type. ```APIDOC ### Example Usage ```go import "google.golang.org/genproto/firestore/bundle" // Create a bundled query for a collection bq := &bundle.BundledQuery{ Parent: "projects/my-project/databases/(default)/documents", QueryType: &bundle.BundledQuery_StructuredQuery{ StructuredQuery: &v1.StructuredQuery{ From: []*v1.StructuredQuery_CollectionSelector{ {CollectionId: "users"}, }, Limit: &wrapperspb.Int32Value{Value: 100}, }, }, LimitType: bundle.BundledQuery_FIRST, } ``` ``` -------------------------------- ### Create a Money Instance Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-common-types.md Example of how to construct a Money object for a specific amount, like $19.99 USD. Ensure correct ISO 4217 currency codes and nanos are used. ```go import "google.golang.org/genproto/googleapis/type/money" // $19.99 price := &money.Money{ CurrencyCode: "USD", Units: 19, Nanos: 990000000, } ``` -------------------------------- ### Example Usage: Creating and Returning Errors with Details Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-rpc-errdetails.md Shows how to create a gRPC status with ErrorInfo details on the server side and return it. Ensure necessary imports are included. ```go import ( "context" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/genproto/googleapis/rpc/errdetails" ) // Create error with details st := status.New(codes.FailedPrecondition, "service not enabled") errorInfo := &errdetails.ErrorInfo{ Reason: "API_DISABLED", Domain: "pubsub.googleapis.com", Metadata: map[string]string{ "resource": "projects/my-project", "service": "pubsub.googleapis.com", }, } st, _ = st.WithDetails(errorInfo) // Return error return nil, st.Err() ``` -------------------------------- ### WriteDraftRequest Constructor Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-actions-sdk-v2.md Example of how to instantiate a `WriteDraftRequest` object. Ensure the `Files` field is populated with appropriate configuration and data. ```go req := &WriteDraftRequest{ Parent: "projects/my-project", Files: &Files{...}, } ``` -------------------------------- ### Create Draft Write Request Example Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-actions-sdk-v2.md Demonstrates how to construct a `WriteDraftRequest` for updating a project draft. The `Files` field should contain `ConfigFile` entries for settings and manifest. ```go import sdk "google.golang.org/genproto/googleapis/actions/sdk/v2" // Create draft write request req := &sdk.WriteDraftRequest{ Parent: "projects/my-actions-project", Files: &sdk.Files{ ConfigFiles: []*sdk.ConfigFile{ { FilePath: "settings.yaml", // ... settings content }, { FilePath: "manifest.json", // ... manifest content }, }, }, } ``` -------------------------------- ### Example Date Usage Scenarios Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-common-types.md Illustrates creating Date objects for different use cases: birthday (month and day only), credit card expiration (year and month), and a full date. Import the date package. ```go import "google.golang.org/genproto/googleapis/type/date" // Birthday (month and day only) birthday := &date.Date{ Month: 3, Day: 15, } // Credit card expiration (year and month) expiration := &date.Date{ Year: 2027, Month: 12, } // Full date today := &date.Date{ Year: 2026, Month: 7, Day: 8, } ``` -------------------------------- ### Initialize NamedQuery with Imports Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/firestore-bundle.md Example of initializing a NamedQuery with necessary imports. This includes setting the query name, parent path for the bundled query, and a specific read time. ```go import ( "google.golang.org/genproto/firestore/bundle" "google.golang.org/protobuf/types/known/timestamppb" ) nq := &bundle.NamedQuery{ Name: "recent_users", BundledQuery: &bundle.BundledQuery{ Parent: "projects/my-project/databases/(default)", // ... bundled query details }, ReadTime: ×tamppb.Timestamp{ Seconds: 1625097600, }, } ``` -------------------------------- ### BundledQuery Constructor Example Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/firestore-bundle.md Demonstrates how to construct a `BundledQuery` object, specifying the parent, a structured query, and the limit type. ```APIDOC ### Constructor ```go bq := &BundledQuery{ Parent: "projects/my-project/databases/(default)", QueryType: &BundledQuery_StructuredQuery{ StructuredQuery: &v1.StructuredQuery{...}, }, LimitType: BundledQuery_FIRST, } ``` ``` -------------------------------- ### Create Date Type Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/INDEX.md Example of creating a Date type instance. Used for representing calendar dates. ```go &date.Date{Year: 2026, Month: 7, Day: 8} ``` -------------------------------- ### WriteDraftRequest Example Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/endpoints.md Example of how to construct a WriteDraftRequest for the Actions SDK service. This is used to write or update a project draft. ```go req := &sdk.WriteDraftRequest{ Parent: "projects/my-actions-project", Files: &sdk.Files{ ConfigFiles: []*sdk.ConfigFile{ { FilePath: "settings.yaml", Content: []byte("..."), }, { FilePath: "manifest.json", Content: []byte("..."), }, }, }, } ``` -------------------------------- ### Create BundledQuery for Collection Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/firestore-bundle.md Example of creating a BundledQuery for a specific collection with a structured query and a limit. Ensure necessary imports are included. ```go import "google.golang.org/genproto/firestore/bundle" // Create a bundled query for a collection bq := &bundle.BundledQuery{ Parent: "projects/my-project/databases/(default)/documents", QueryType: &bundle.BundledQuery_StructuredQuery{ StructuredQuery: &v1.StructuredQuery{ From: []*v1.StructuredQuery_CollectionSelector{ {CollectionId: "users"}, }, Limit: &wrapperspb.Int32Value{Value: 100}, }, }, LimitType: bundle.BundledQuery_FIRST, } ``` -------------------------------- ### Example QuotaFailure Usage Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-rpc-errdetails.md Demonstrates constructing a `QuotaFailure` object and attaching it to a gRPC status with `ResourceExhausted` code. ```go quotaFailure := &errdetails.QuotaFailure{ Violations: []*errdetails.QuotaFailure_Violation{ { Subject: "projects/my-project", Description: "Exceeded daily quota: 10000 operations/day", }, }, } st, _ := status.New(codes.ResourceExhausted, "quota exceeded"). WithDetails(quotaFailure) ``` -------------------------------- ### Decimal Constructor Examples Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-common-types.md Constructs Decimal objects using string values. Useful for financial calculations or high-precision numbers. Requires importing the decimal package. ```go import "google.golang.org/genproto/googleapis/type/decimal" pi := &decimal.Decimal{ Value: "3.14159265358979323846", } // Large numbers bigNumber := &decimal.Decimal{ Value: "123456789012345678901234567890.123456789", } ``` ```go // Price with exact precision price := &decimal.Decimal{ Value: "19.99", } // Latitude/longitude with high precision latitude := &decimal.Decimal{ Value: "40.7128", } ``` -------------------------------- ### Create BundledQuery Type Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/INDEX.md Example of creating a BundledQuery type instance. Used in Firestore for bundle operations. ```go &bundle.BundledQuery{Parent: "..."} ``` -------------------------------- ### Example Usage of BadRequest Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-rpc-errdetails.md Shows how to construct a BadRequest detail and attach it to an RPC status. This is useful for returning detailed error information to the client. ```go import "google.golang.org/genproto/googleapis/rpc/errdetails" badRequest := &errdetails.BadRequest{ FieldViolations: []*errdetails.BadRequest_FieldViolation{ { Field: "password", Description: "Password must be at least 8 characters", }, { Field: "name", Description: "Name is required", }, }, } st, _ := status.New(codes.InvalidArgument, "invalid request"). WithDetails(badRequest) return nil, st.Err() ``` -------------------------------- ### Construct QuotaFailure Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-rpc-errdetails.md Example of creating a `QuotaFailure` object with multiple `QuotaFailure_Violation` entries, detailing different resource limits. ```go quotaFailure := &errdetails.QuotaFailure{ Violations: []*errdetails.QuotaFailure_Violation{ { Subject: "projects/my-project", Description: "Exceeded daily API call limit: 10000/day", }, { Subject: "projects/my-project/users/user@example.com", Description: "Exceeded per-user quota: 100/hour", }, }, } ``` -------------------------------- ### DateTimeRange Constructor Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-common-types.md Constructs a DateTimeRange object with specified start and end times. Requires importing the datetime and date_time_range packages. ```go import ( "google.golang.org/genproto/googleapis/type/datetime" "google.golang.org/genproto/googleapis/type/date_time_range" ) dtRange := &date_time_range.DateTimeRange{ StartDateTime: &datetime.DateTime{ Year: 2026, Month: 1, Day: 1, Hours: 0, }, EndDateTime: &datetime.DateTime{ Year: 2026, Month: 12, Day: 31, Hours: 23, }, } ``` -------------------------------- ### Standard Resource Naming Patterns Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md Services use standardized resource naming patterns for consistent resource identification. Examples include projects, drafts, and versions. ```text projects/{project} projects/{project}/draft projects/{project}/preview projects/{project}/versions/{version} projects/{project}/datasets/{dataset} projects/{project}/locations/{location}/resources/{resource} ``` -------------------------------- ### Create ErrorInfo Type Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/INDEX.md Example of creating an ErrorInfo type instance. Used for providing detailed error information in RPC responses. ```go &errdetails.ErrorInfo{Reason: "API_DISABLED"} ``` -------------------------------- ### Example Usage: Extracting Error Details on Client Side Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-rpc-errdetails.md Demonstrates how to extract ErrorInfo details from a received gRPC error status on the client side. This involves checking the error type and iterating through details. ```go err := someRPCCall() st, ok := status.FromError(err) if ok { for _, detail := range st.Details() { if errInfo, ok := detail.(*errdetails.ErrorInfo); ok { fmt.Printf("Error: %s in %s\n", errInfo.Reason, errInfo.Domain) } } } ``` -------------------------------- ### DateTimeRange Type Definition Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-common-types.md Defines a range between two points in time, inclusive of both start and end. ```go type DateTimeRange struct { StartDateTime *DateTime // Start time (inclusive) EndDateTime *DateTime // End time (inclusive) } ``` -------------------------------- ### Create and Use Access Approval Client Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/overview.md This snippet demonstrates how to create a client for the Access Approval service and make a request. Ensure you have the necessary context and import the correct packages. ```go import ( "context" "google.golang.org/genproto/googleapis/cloud/accessapproval/apiv1" accessapprovalpb "google.golang.org/genproto/googleapis/cloud/accessapproval/apiv1/accessapprovalpb" ) // Create service client client, err := apiv1.NewAccessApprovalClient(ctx) // Create request message req := &accessapprovalpb.ListApprovalRequestsMessage{ Parent: "projects/my-project", } // Call service method resp, err := client.ListApprovalRequests(ctx, req) ``` -------------------------------- ### Create ErrorInfo Constructor Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-rpc-errdetails.md Demonstrates how to create an instance of ErrorInfo with specific reason, domain, and metadata. ```go errInfo := &errdetails.ErrorInfo{ Reason: "API_DISABLED", Domain: "googleapis.com", Metadata: map[string]string{ "resource": "projects/123", "service": "pubsub.googleapis.com", }, } ``` -------------------------------- ### Go Service Client Pattern for Actions SDK Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/README.md Demonstrates establishing a gRPC connection and creating an Actions SDK client to write a draft. ```go import ( "context" "google.golang.org/genproto/googleapis/actions/sdk/v2" "google.golang.org/grpc" ) conn, err := grpc.Dial("actions.googleapis.com:443") deferr conn.Close() client := sdk.NewActionsSdkClient(conn) resp, err := client.WriteDraft(context.Background(), &sdk.WriteDraftRequest{ Parent: "projects/my-project", }) ``` -------------------------------- ### Create a NamedQuery Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/firestore-bundle.md Demonstrates how to construct a NamedQuery object, which associates a query with a name for use in bundle files. Ensure to provide the query name, bundled query details, and a read time. ```go nq := &NamedQuery{ Name: "my-named-query", BundledQuery: &BundledQuery{...}, ReadTime: timestamppb.Now(), } ``` -------------------------------- ### Fraction Constructor Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-common-types.md Illustrates how to create Fraction objects for one-half and three-quarters. Ensure you import the correct package. ```go import "google.golang.org/genproto/googleapis/type/fraction" // One-half half := &fraction.Fraction{ Numerator: 1, Denominator: 2, } // Three-quarters threeQuarters := &fraction.Fraction{ Numerator: 3, Denominator: 4, } ``` -------------------------------- ### Create a Date Instance Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-common-types.md Demonstrates how to create a new Date object using its struct literal syntax. Ensure the date package is imported. ```go import "google.golang.org/genproto/googleapis/type/date" d := &date.Date{ Year: 2026, Month: 7, Day: 8, } ``` -------------------------------- ### Repeated Field Types in Go Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/types.md Examples of how repeated fields (arrays/slices) and maps are represented in Go Protobuf definitions. ```go []string // Repeated strings []int32 // Repeated integers []*SomeMessage // Repeated messages map[string]string // String map map[string]*SomeMessage // Message map ``` -------------------------------- ### Create WriteDraftRequest Type Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/INDEX.md Example of creating a WriteDraftRequest type instance. Used in the Actions SDK for draft operations. ```go &sdk.WriteDraftRequest{Parent: "..."} ``` -------------------------------- ### DateRange Type Definition Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-common-types.md Defines the structure for representing a range between two dates, inclusive of both start and end dates. ```go type DateRange struct { StartDate *Date // Start date (inclusive) EndDate *Date // End date (inclusive) } ``` -------------------------------- ### Create GCP Project Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md Use this command to create a new Google Cloud project. ```bash gcloud projects create my-project ``` -------------------------------- ### Create a Draft Resource Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-actions-sdk-v2.md Instantiate a Draft resource with its name and validation results. The name should follow the format `projects/{project}/draft`. ```go draft := &sdk.Draft{ Name: "projects/my-project/draft", ValidationResults: &sdk.ValidationResults{ Results: []*sdk.ValidationResult{}, }, } ``` -------------------------------- ### Triggering FAILED_PRECONDITION Error Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/errors.md Demonstrates triggering a FAILED_PRECONDITION error, for example, when a required service is not enabled. This error can include PreconditionFailure details. ```go // Action SDK API not enabled req := &sdk.WriteDraftRequest{...} resp, err := client.WriteDraft(ctx, req) // Returns FAILED_PRECONDITION with PreconditionFailure ``` -------------------------------- ### ListSampleProjects Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/endpoints.md Lists sample Actions projects. ```APIDOC ## ListSampleProjects ### Description List sample Actions projects. ### Method GET ### Endpoint /v1beta1/{parent=projects/*}/sampleProjects ### Parameters #### Path Parameters - **parent** (string) - Yes - Parent resource ### Response #### Success Response (200) - **sampleProjects** ([]*SampleProject) - List of sample projects #### Error Response - **PERMISSION_DENIED** - User lacks read permission ``` -------------------------------- ### Create BundleMetadata Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/firestore-bundle.md Instantiate a BundleMetadata object with essential details like ID, creation time, version, document count, and size. ```go bundleMetadata := &bundle.BundleMetadata{ Id: "bundle-123", CreateTime: timestamppb.Now(), Version: 1, TotalDocuments: 50, TotalBytes: 102400, } ``` -------------------------------- ### Create WritePreviewRequest from Files Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-actions-sdk-v2.md Construct a WritePreviewRequest to create or update a preview using files. This includes specifying the parent project, the source as files, and preview settings like sandbox mode. ```go // Preview from files req := &sdk.WritePreviewRequest{ Parent: "projects/my-project", Source: &sdk.WritePreviewRequest_Files{ Files: &sdk.Files{ ConfigFiles: []*sdk.ConfigFile{...}, }, }, PreviewSettings: &sdk.WritePreviewRequest_PreviewSettings{ Sandbox: true, }, } ``` -------------------------------- ### Interval Type Definition Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-common-types.md Defines a structure to represent a contiguous portion of time, including a start (inclusive) and end (exclusive) timestamp. ```go type Interval struct { StartTime *timestamppb.Timestamp // Start time (inclusive) EndTime *timestamppb.Timestamp // End time (exclusive) } ``` -------------------------------- ### Go Service Client Usage Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/modules.md Shows how to import generated types from go-genproto and use the client from a cloud-specific library. Instantiate the client using the appropriate NewClient function. ```go // Types from go-genproto import "google.golang.org/genproto/googleapis/cloud/storage/v1" // Client from cloud-specific library import "cloud.google.com/go/storage" // Usage client := storage.NewClient(ctx) ``` -------------------------------- ### Enable Google Cloud APIs Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md Enable the required APIs for your Google Cloud project. ```bash gcloud services enable actions.googleapis.com gcloud services enable storage.googleapis.com ``` -------------------------------- ### Go Package Import Paths Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/modules.md Illustrates the import paths for generated message types and service clients. Use the genproto path for types and the cloud.google.com/go path for service clients. ```go // Message types import "google.golang.org/genproto/googleapis/service/version" // Service client (in cloud.google.com/go) import "cloud.google.com/go/service/apiv1" ``` -------------------------------- ### PreconditionFailure Structure and Usage Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-rpc-errdetails.md This snippet demonstrates the Go type definition for PreconditionFailure and its nested Violation type, along with examples of how to construct and use them in RPC error details. ```APIDOC ## PreconditionFailure Describes violations of preconditions required for operation. ### Type Definition ```go type PreconditionFailure struct { Violations []*PreconditionFailure_Violation } ``` ### Violation Type ```go type PreconditionFailure_Violation struct { Type string // Violation type identifier Subject string // Resource subject Description string // Violation description } ``` ### Constructor Example ```go preconditionFailure := &errdetails.PreconditionFailure{ Violations: []*errdetails.PreconditionFailure_Violation{ { Type: "TERMS_OF_SERVICE", Subject: "users/user@example.com", Description: "User must accept terms of service", }, }, } ``` ### Fields #### PreconditionFailure Fields | Field | Type | Required | Description | |-------|------|----------|-------------| | Violations | []*PreconditionFailure_Violation | Yes | List of preconditions not met | #### Violation Fields | Field | Type | Required | Description | |-------|------|----------|-------------| | Type | string | Yes | Violation type (e.g., TERMS_OF_SERVICE) | | Subject | string | Yes | Resource subject | | Description | string | Yes | Why precondition failed | ### Example Usage ```go preconditionFailure := &errdetails.PreconditionFailure{ Violations: []*errdetails.PreconditionFailure_Violation{ { Type: "SERVICE_DISABLED", Subject: "projects/my-project", Description: "The Cloud Storage service is not enabled", }, }, } st, _ := status.New(codes.FailedPrecondition, "precondition failed"). WithDetails(preconditionFailure) ``` ``` -------------------------------- ### Go Authentication with Explicit Key File Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md Configure Go client libraries to use credentials from a specified JSON key file. ```go import ( "cloud.google.com/go/compute/metadata" "google.golang.org/api/option" credentials "google.golang.org/api/transport/google" ) // Or with explicit key file creds, _ := credentials.GetCredentials( ctx, option.WithCredentialsFile("path/to/key.json"), ) ``` -------------------------------- ### Create GCP Service Account Credentials Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md Generate a JSON key file for your service account. ```bash gcloud iam service-accounts keys create key.json \ --iam-account=my-service-account@my-project.iam.gserviceaccount.com ``` -------------------------------- ### Process Multiple Operations Using Batch Requests Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md Improve performance by batching multiple operations into a single request. This example shows creating a slice of WriteDraftRequest and processing them. ```go // Batch requests requests := []*sdk.WriteDraftRequest{ {Parent: "projects/proj1", Files: files1}, {Parent: "projects/proj2", Files: files2}, } // Process serially or in parallel depending on requirements for _, req := range requests { resp, err := client.WriteDraft(ctx, req) // Handle response } ``` -------------------------------- ### Common CEL Expressions Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-common-types.md Provides examples of various Common Expression Language (CEL) expressions, including simple comparisons, string operations, logical operations, list operations, and timestamp operations. ```cel "resource.name == 'admin'" ``` ```cel "resource.name.startsWith('projects/')" ``` ```cel "resource.tag == 'prod' && resource.env == 'production'" ``` ```cel "resource.labels.size() > 0 && 'owner' in resource.labels" ``` ```cel "now - resource.created < duration('24h')" ``` -------------------------------- ### Basic gRPC Client Creation Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md Create a gRPC client connection using grpc.DialContext. Specify the target address and transport credentials. Remember to close the connection when done. ```go import ( "context" "google.golang.org/genproto/googleapis/actions/sdk/v2" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) // Create connection with default options conn, err := grpc.DialContext( ctx, "actions.googleapis.com:443", grpc.WithTransportCredentials(creds), ) defer conn.Close() // Create client client := sdk.NewActionsSdkClient(conn) ``` -------------------------------- ### Create PreconditionFailure with Violation Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-rpc-errdetails.md Demonstrates how to construct a PreconditionFailure object with a specific violation, such as a terms of service agreement. ```go preconditionFailure := &errdetails.PreconditionFailure{ Violations: []*errdetails.PreconditionFailure_Violation{ { Type: "TERMS_OF_SERVICE", Subject: "users/user@example.com", Description: "User must accept terms of service", }, }, } ``` -------------------------------- ### SampleProject Type Definition Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-actions-sdk-v2.md Defines the structure for a sample Actions project, including its name and description. ```go type SampleProject struct { Name string // Sample project name Description string // Description } ``` -------------------------------- ### Import Paths for Genproto Packages Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/README.md Illustrates common import paths for accessing various Google API services and types within the genproto module. Ensure your project is set up to use Go modules. ```go google.golang.org/genproto/firestore/bundle google.golang.org/genproto/googleapis/actions/sdk/v2 google.golang.org/genproto/googleapis/rpc/errdetails google.golang.org/genproto/googleapis/type/date google.golang.org/genproto/googleapis/type/datetime google.golang.org/genproto/googleapis/type/money // ... and 100+ more service packages ``` -------------------------------- ### Create BundledDocumentMetadata Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/firestore-bundle.md Shows how to create a BundledDocumentMetadata object. This metadata includes the document's name, existence status, read time, and the queries it matches. ```go metadata := &bundle.BundledDocumentMetadata{ Name: "projects/my-project/databases/(default)/documents/users/user123", Exists: true, ReadTime: ×tamppb.Timestamp{ Seconds: 1625097600, }, Queries: []string{"recent_users", "active_users"}, } ``` -------------------------------- ### Protobuf Service Server Interface (Go) Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/types.md Defines the interface for implementing a protobuf service server. Includes methods for unary and streaming RPCs. ```go type MyServiceServer interface { MyMethod(context.Context, *MyRequest) (*MyResponse, error) MyStreamingMethod(MyService_MyStreamingMethodServer) error } ``` -------------------------------- ### Create LatLng Instance Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-common-types.md Demonstrates how to create an instance of the LatLng type, representing the Empire State Building's coordinates. Ensure the 'google.golang.org/genproto/googleapis/type/latlng' package is imported. ```go import "google.golang.org/genproto/googleapis/type/latlng" // Empire State Building location := &latlng.LatLng{ Latitude: 40.7484, Longitude: -73.9857, } ``` -------------------------------- ### WritePreview Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/endpoints.md Creates or updates a preview for testing. This is a server streaming RPC. ```APIDOC ## WritePreview (Server Streaming) ### Description Create or update a preview for testing. ### Request Type `WritePreviewRequest` ### Parameters #### Request Body - **Parent** (string) - Required - Parent: `projects/{project}` - **Source** (isWritePreviewRequest_Source) - Required - Data source (oneof) - `Files`: Stream files directly - `Draft`: Use current draft - `SubmittedVersion`: Use existing version - **PreviewSettings** (*WritePreviewRequest_PreviewSettings) - Required - Preview configuration ### Response Type `Preview` ### Success Response (OK) - **Name** (string) - Preview ID: `projects/{project}/preview` - **ValidationResults** (*ValidationResults) - Validation results - **SimulatorUrl** (string) - URL to test preview ### Error Codes - **OK**: Preview created/updated - **INVALID_ARGUMENT**: Invalid source or settings - **FAILED_PRECONDITION**: Source not ready - **RESOURCE_EXHAUSTED**: Preview quota exceeded ### Request Example ```go // From files req := &sdk.WritePreviewRequest{ Parent: "projects/my-project", Source: &sdk.WritePreviewRequest_Files{ Files: &sdk.Files{...}, }, PreviewSettings: &sdk.WritePreviewRequest_PreviewSettings{ Sandbox: true, }, } // From draft req := &sdk.WritePreviewRequest{ Parent: "projects/my-project", Source: &sdk.WritePreviewRequest_Draft{ Draft: &sdk.WritePreviewRequest_ContentFromDraft{}, }, PreviewSettings: &sdk.WritePreviewRequest_PreviewSettings{}, } ``` ``` -------------------------------- ### Create GCP Service Account and Assign Role Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md Create a service account and assign it the App Engine Admin role for the project. ```bash gcloud iam service-accounts create my-service-account gcloud projects add-iam-policy-binding my-project \ --member=serviceAccount:my-service-account@my-project.iam.gserviceaccount.com \ --role=roles/appengine.admin ``` -------------------------------- ### Regenerate Proto Files with Protoc Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md Use this command to regenerate Go proto files. Ensure paths are set to source_relative for proper import handling. ```bash protoc \ --go_out=. \ --go-grpc_out=. \ --go_opt=paths=source_relative \ --go-grpc_opt=paths=source_relative \ google/actions/sdk/v2/actions_sdk.proto ``` -------------------------------- ### Create WritePreviewRequest from Draft Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-actions-sdk-v2.md Construct a WritePreviewRequest to create or update a preview using the current draft. Specify the parent project and the source as a draft reference, along with preview settings. ```go // Preview from draft req := &sdk.WritePreviewRequest{ Parent: "projects/my-project", Source: &sdk.WritePreviewRequest_Draft{ Draft: &sdk.WritePreviewRequest_ContentFromDraft{}, }, PreviewSettings: &sdk.WritePreviewRequest_PreviewSettings{}, } ``` -------------------------------- ### Create BadRequest Instance Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-rpc-errdetails.md Demonstrates how to create an instance of BadRequest with multiple field violations. ```go badRequest := &errdetails.BadRequest{ FieldViolations: []*errdetails.BadRequest_FieldViolation{ { Field: "message.user.email", Description: "Email must be valid format", }, { Field: "message.age", Description: "Age must be >= 0", }, }, } ``` -------------------------------- ### CreateVersion Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/endpoints.md Creates a new released version. This is a server streaming RPC. ```APIDOC ## CreateVersion (Server Streaming) ### Description Create a new released version. ### Request Type `CreateVersionRequest` ### Parameters #### Request Body - **Parent** (string) - Required - Parent: `projects/{project}` - **Files** (*Files) - Required - Version files - **ReleaseChannel** (string) - Optional - Target release channel - `actions.channels.Production`: Production release - `actions.channels.ClosedBeta`: Closed beta release - `actions.channels.Alpha`: Alpha release ### Response Type `Version` ### Success Response (OK) - **Name** (string) - Version ID: `projects/{project}/versions/{version}` - **CreateTime** (*Timestamp) - Creation timestamp - **State** (VersionState) - Version state (DRAFT, ACTIVE, SUPERSEDED) ### Error Codes - **OK**: Version created - **INVALID_ARGUMENT**: Invalid files or channel - **FAILED_PRECONDITION**: Validation errors block release - **RESOURCE_EXHAUSTED**: Version quota exceeded ### Request Example ```go req := &sdk.CreateVersionRequest{ Parent: "projects/my-project", ReleaseChannel: "actions.channels.Production", Files: &sdk.Files{ ConfigFiles: []*sdk.ConfigFile{...}, }, } ``` ``` -------------------------------- ### WritePreview Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-actions-sdk-v2.md Creates a preview of the current project state. This is useful for testing recent changes before releasing them. ```APIDOC ## WritePreview ### Description Creates a preview. ### Method POST ### Endpoint /v2/projects/{projectId}/previews ### Request Body - **preview** (Preview) - Required - The preview object to create. ### Response #### Success Response (200) - **preview** (Preview) - The created preview object. ``` -------------------------------- ### Creating a Date Message in Go Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/README.md Instantiate a date.Date message with year, month, and day. ```go // Date d := &date.Date{Year: 2026, Month: 7, Day: 8} ``` -------------------------------- ### Importing Common Type Packages in Go Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/README.md Import common type packages like date and datetime for use in Go. ```go // Common Types import "google.golang.org/genproto/googleapis/type/date" import "google.golang.org/genproto/googleapis/type/datetime" ``` -------------------------------- ### Timeout with Fallback Strategy Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/errors.md Demonstrates a timeout strategy where an initial short timeout is used, and if a DeadlineExceeded error occurs, a retry with a longer timeout is attempted. ```go // Try with short timeout ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) resp, err := client.MyMethod(ctx, req) cancel() if err != nil { st, _ := status.FromError(err) if st.Code() == codes.DeadlineExceeded { // Try again with longer timeout ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) resp, err = client.MyMethod(ctx, req) cancel() } } ``` -------------------------------- ### Create and Attach PreconditionFailure to Status Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-rpc-errdetails.md Shows how to create a PreconditionFailure and attach it to a gRPC status object, indicating a failed precondition. ```go preconditionFailure := &errdetails.PreconditionFailure{ Violations: []*errdetails.PreconditionFailure_Violation{ { Type: "SERVICE_DISABLED", Subject: "projects/my-project", Description: "The Cloud Storage service is not enabled", }, }, } st, _ := status.New(codes.FailedPrecondition, "precondition failed"). WithDetails(preconditionFailure) ``` -------------------------------- ### Go Authentication with Default Credentials Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md Configure Go client libraries to use default credentials, typically sourced from the GOOGLE_APPLICATION_CREDENTIALS environment variable. ```go import ( "cloud.google.com/go/compute/metadata" "google.golang.org/api/option" credentials "google.golang.org/api/transport/google" ) // Use default credentials (from GOOGLE_APPLICATION_CREDENTIALS) creds, _ := credentials.GetCredentials(ctx) ``` -------------------------------- ### Creating an ErrorInfo Message in Go Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/README.md Instantiate an errdetails.ErrorInfo message with reason and domain. ```go // ErrorInfo errInfo := &errdetails.ErrorInfo{ Reason: "API_DISABLED", Domain: "googleapis.com", } ``` -------------------------------- ### Expr Constructor Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-common-types.md Shows how to construct an Expr object for a CEL permission checking expression. This includes setting the expression, title, and description. ```go import "google.golang.org/genproto/googleapis/type/expr" // CEL expression for permission checking expr := &expr.Expr{ Expression: "resource.name.startsWith('projects/_/buckets/example-bucket') && " + "resource.matchTag('env', 'prod')", Title: "Sample IAM Policy Condition", Description: "Checks if resource is in production", } ``` -------------------------------- ### WritePreviewRequest Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-actions-sdk-v2.md Streaming RPC request for creating or updating a preview of an Actions project. ```APIDOC ## WritePreviewRequest ### Description Streaming RPC request for creating or updating a preview. ### Type Definition ```go type WritePreviewRequest struct { Parent string // Parent project name Source isWritePreviewRequest_Source // Union field for source PreviewSettings *WritePreviewRequest_PreviewSettings // Preview configuration } ``` ### Union Types for Source - `*WritePreviewRequest_Files`: Stream Files directly - `*WritePreviewRequest_Draft`: Use current draft - `*WritePreviewRequest_SubmittedVersion`: Use an existing version ### Methods #### GetParent() string Returns parent in format `projects/{project}`. #### GetSource() isWritePreviewRequest_Source Returns the source data for the preview. #### GetFiles() *Files Returns Files if source is Files type. #### GetDraft() *WritePreviewRequest_ContentFromDraft Returns Draft reference if source is Draft type. #### GetSubmittedVersion() *WritePreviewRequest_ContentFromSubmittedVersion Returns Version reference if source is SubmittedVersion type. #### GetPreviewSettings() *WritePreviewRequest_PreviewSettings Returns preview configuration settings. ### Fields Table | Field | Type | Required | Description | |-------|------|----------|-------------| | Parent | string | Yes | Parent project: `projects/{project}` | | Source | isWritePreviewRequest_Source | Yes | Data source (Files, Draft, or Version) | | PreviewSettings | *WritePreviewRequest_PreviewSettings | Yes | Preview configuration | ### Example Usage ```go // Preview from files req := &sdk.WritePreviewRequest{ Parent: "projects/my-project", Source: &sdk.WritePreviewRequest_Files{ Files: &sdk.Files{ ConfigFiles: []*sdk.ConfigFile{...}, }, }, PreviewSettings: &sdk.WritePreviewRequest_PreviewSettings{ Sandbox: true, }, } // Preview from draft req := &sdk.WritePreviewRequest{ Parent: "projects/my-project", Source: &sdk.WritePreviewRequest_Draft{ Draft: &sdk.WritePreviewRequest_ContentFromDraft{}, }, PreviewSettings: &sdk.WritePreviewRequest_PreviewSettings{}, } ``` ``` -------------------------------- ### Protobuf Service Client Interface (Go) Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/types.md Defines the interface for implementing a protobuf service client. Includes methods for making unary and streaming RPC calls. ```go type MyServiceClient interface { MyMethod(context.Context, *MyRequest, ...grpc.CallOption) (*MyResponse, error) MyStreamingMethod(context.Context, ...grpc.CallOption) (MyService_MyStreamingMethodClient, error) } ``` -------------------------------- ### Create RetryInfo Instance Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-rpc-errdetails.md Constructs a RetryInfo object with a specified retry delay. ```go retryInfo := &errdetails.RetryInfo{ RetryDelay: &durationpb.Duration{ Seconds: 5, Nanos: 0, }, } ``` -------------------------------- ### Importing Google Actions SDK Types in Go Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/README.md Import the Google Actions SDK v2 package for Go. ```go // Google Actions SDK import "google.golang.org/genproto/googleapis/actions/sdk/v2" ``` -------------------------------- ### Verify Protobuf Runtime Version in Go Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md Generated Go files include version checks to ensure compatibility. Ensure your project meets the minimum required versions for google.golang.org/protobuf and github.com/golang/protobuf. ```go const ( _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) ``` -------------------------------- ### Create BundleElement with Document Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/firestore-bundle.md Construct a BundleElement containing a Document. This represents a single document within the bundle stream. ```go // Document element elem := &bundle.BundleElement{ ElementType: &bundle.BundleElement_Document{ Document: &v1.Document{...}, }, } ``` -------------------------------- ### Go Workspace Configuration (go.work) Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md Configure Go workspace mode to manage multiple modules, including local submodules. This is useful for monorepos or projects with complex internal dependencies. ```go go 1.25.8 use ( . ./googleapis/api ./googleapis/cloud/accessapproval // ... individual service submodules ) ``` -------------------------------- ### ListVersions Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/endpoints.md Lists project versions. ```APIDOC ## ListVersions ### Description List project versions. ### Method GET ### Endpoint /v1beta1/{parent=projects/*}/versions ### Parameters #### Path Parameters - **parent** (string) - Yes - Parent: `projects/{project}` #### Query Parameters - **pageSize** (int32) - No - Results per page (default 10) - **pageToken** (string) - No - Pagination token ### Response #### Success Response (200) - **versions** ([]*Version) - Version list - **nextPageToken** (string) - Pagination token for next page #### Error Response - **INVALID_ARGUMENT** - Invalid page size - **NOT_FOUND** - Project not found ``` -------------------------------- ### Configure gRPC Request with Call Options Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md All gRPC RPC calls can accept optional CallOption arguments to customize behavior like credentials, compression, and message size limits. ```go resp, err := client.MyMethod( ctx, req, grpc.PerRPCCredentials(creds), // Per-RPC credentials grpc.UseCompressor("gzip"), // Enable compression grpc.MaxCallRecvMsgSize(100 * 1024 * 1024), // Max receive size grpc.MaxCallSendMsgSize(100 * 1024 * 1024), // Max send size ) ``` -------------------------------- ### Standard Protobuf Message Methods (Go) Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/types.md These methods are automatically generated for every protobuf message. Use Reset to clear fields and String for debugging. ProtoMessage and ProtoReflect provide reflection capabilities. Field accessors are generated for each field. ```go func (x *MyMessage) Reset() // Reset to zero value func (x *MyMessage) String() string // Debug string representation func (*MyMessage) ProtoMessage() // Marker interface func (x *MyMessage) ProtoReflect() protoreflect.Message // Reflection API func (x *MyMessage) Descriptor() ([]byte, []int) // Descriptor info // Field accessors (one per field) func (x *MyMessage) GetFieldName() FieldType func (x *MyMessage) SetFieldName(FieldType) // For mutable fields ``` -------------------------------- ### Create BundleElement with NamedQuery Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/firestore-bundle.md Construct a BundleElement containing a NamedQuery. This allows for including predefined queries within the bundle stream. ```go // Named query element elem := &bundle.BundleElement{ ElementType: &bundle.BundleElement_NamedQuery{ NamedQuery: &bundle.NamedQuery{...}, }, } ``` -------------------------------- ### Google Actions SDK v2 Listing Types Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/types.md Request and response types for listing resources within the Google Actions SDK v2, such as sample projects, channels, and versions. ```go type ListSampleProjectsRequest struct // Request to list samples type ListSampleProjectsResponse struct // Response with sample list type ListReleaseChannelsRequest struct // Request to list channels type ListReleaseChannelsResponse struct // Response with channels type ListVersionsRequest struct // Request to list versions type ListVersionsResponse struct // Response with versions ``` -------------------------------- ### Run Changefinder with Custom Directory Source: https://github.com/googleapis/go-genproto/blob/main/internal/actions/cmd/changefinder/README.md Use this command to specify a different Git repository directory to analyze. Ensure the path is absolute. ```bash go run ./internal/actions/cmd/changefinder -dir /path/to/your/go/repo ``` -------------------------------- ### Preview Type Definition Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/api-reference/google-actions-sdk-v2.md Defines the structure for a preview resource used in testing Actions. Includes identifier, validation results, and simulator URL. ```go type Preview struct { Name string // Preview identifier ValidationResults *ValidationResults // Validation results SimulatorUrl string // URL to test preview } ``` -------------------------------- ### Go gRPC Dial with Service Account JSON Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md Establish a gRPC connection using a service account JSON file for authentication. ```go import "google.golang.org/api/transport/grpc" conn, _ := grpc.Dial( ctx, "actions.googleapis.com:443", option.WithCredentialsFile("key.json"), ) ``` -------------------------------- ### Enable gRPC Debug Logging Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md Configure gRPC to output debug logs to standard error. This requires importing the grpclog package and setting a custom logger. ```go import "google.golang.org/grpc/grpclog" logger := grpclog.NewLoggerV2(os.Stderr, os.Stderr, os.Stderr) grpclog.SetLoggerV2(logger) ``` -------------------------------- ### Customize JSON Marshaling Options Source: https://github.com/googleapis/go-genproto/blob/main/_autodocs/configuration.md Configure Protobuf JSON marshaling with custom options such as using proto field names, emitting unpopulated fields, and specifying indentation for pretty-printing. ```go marshaler := &protojson.MarshalOptions{ UseProtoNames: true, // Use proto field names, not lowerCamelCase EmitUnpopulated: true, // Include zero-valued fields Indent: " ", // Pretty-print with indentation } jsonData, _ := marshaler.Marshal(msg) ```