googleapis/go-genproto

repository·main·Indexed 20 days ago

https://github.com/googleapis/go-genproto

Generated Go packages for common protocol buffer types and the gRPC code required to interact with Google's gRPC APIs. This experimental repository includes the genproto package and tools like changefinder for identifying changed submodules. It provides support for various Google APIs, including the Alert Center API (v1beta1) for managing customer alerts, metadata, and feedback, as well as common types like the LaunchStage enumeration for Google Cloud Platform feature lifecycles.

Tokens
18K
Snippets
55
Records
89
Agent score
65%

What's inside go-genproto

  1. Use changefinder to identify changed submodules

    main

    The changefinder tool compares the current branch against a base reference (defaulting to origin/main) to identify which submodules have changed. It automatically excludes any submodules located within an internal directory. By default, it outputs a newline-delimited list of changed submodules to stdout.

    go run ./internal/actions/cmd/changefinder
  2. Important considerations for using go-genproto

    main

    Before integrating this repository into your project, be aware of the following:

    • Experimental Status: This repository is currently experimental. The package structure is subject to change.
    • Source Verification: Because the structure may change, check the original source repositories for the specific protocol buffer's associated service to confirm its status.
    • Well-known Types: Historically, the protobuf directory contained generated code for well-known types. These are now hosted in the google.golang.org/protobuf module. The packages in this repository use type aliases to forward declarations from the protobuf module to the google.golang.org/protobuf module.
  3. Install the Go generated proto packages

    main

    You can install the generated Go packages for common protocol buffer types and gRPC code using the following command.

    Warning: As of May 26, 2023, new submodules were introduced. You should upgrade your dependencies before 2024-03-01 to avoid ambiguous import errors with google.golang.org/genproto.

    ```bash
    go get google.golang.org/genproto/...\n```
  4. Define Universal Actions for Gmail add-ons

    main

    UniversalAction represents an action that is always available in the add-on toolbar menu, regardless of the current message context. Each action requires a user-visible Text description and one of two action types:

    1. OpenLink: Opens a specific URL when the action is triggered.
    2. RunFunction: Calls a specific endpoint (function) when the action is triggered.

    Use the isUniversalAction_ActionType interface to implement these types.

    // Example of a UniversalAction that runs a function
    action := &gmail.UniversalAction{
        Text: "Add a new contact",
        ActionType: &gmail.UniversalAction_RunFunction{
            RunFunction: "myFunctionName",
        },
    }
  5. Field message types in Google Drive Labels v2

    main
    The field.proto definitions in the Google Drive Labels v2 API describe the structure of label fields. These message types allow for the configuration of field properties, including text options, integer options, date options, selection options, and user options. They also support schema capabilities such as defining display names, descriptions, and badge configurations (colors and priorities).
  6. Define Google Sheets add-on manifest triggers

    main

    The SheetsAddOnManifest message type is used to configure specific triggers for a Google Sheets add-on. It allows you to override common homepage triggers and define specific behavior when file scope authorization is granted.

    Key fields:

    • HomepageTrigger: An optional *type.HomepageExtensionPoint that overrides the configuration from addOns.common.homepageTrigger.
    • OnFileScopeGrantedTrigger: A *SheetsExtensionPoint that defines the endpoint to execute when file scope authorization is granted for a specific document/user pair.
    import "google.golang.org/genproto/googleapis/apps/script/type/sheets"
    
    manifest := &sheets.SheetsAddOnManifest{
        HomepageTrigger: homepageExtensionPoint, // type.HomepageExtensionPoint
        OnFileScopeGrantedTrigger: &sheets.SheetsExtensionPoint{
            RunFunction: "myOnScopeGrantedFunction",
        },
    }
  7. Use Google Drive label field message types

    main

    The google.apps.drive.labels.v2 package provides message types for defining fields within Google Drive labels. The core type is Field, which uses a oneof structure to support different data types for label fields, including text, integers, dates, selections, and user-defined options.

    Key components of a Field include:

    • Type-specific options: TextOptions, IntegerOptions, DateOptions, SelectionOptions, and UserOptions.
    • Metadata: Properties, DisplayHints, SchemaCapabilities, and AppliedCapabilities.
    • Lifecycle information: Lifecycle (tracking creators, updaters, and timestamps) and LockStatus.
    • Selection specific types: SelectionOptions can contain a list of Choice objects, each with its own properties, display hints, and lifecycle metadata.
  8. How ByteStream resumable writes work

    main

    ByteStream is designed for reliable, large-scale data transfers. The core pattern for handling interruptions is:

    1. Initiate Write: Start a Write stream with WriteOffset: 0.
    2. Handle Failures: If the stream breaks, do not assume all sent data was saved.
    3. Query Status: Call QueryWriteStatus(resource_name) to get the committed_size.
    4. Resume: Start a new Write stream. Set the WriteOffset to the committed_size received in step 3. Begin sending data from that point forward.
    5. Finalize: The write is not permanent until a WriteRequest is sent with finish_write: true and the server responds with a WriteResponse.
  9. Define Contextual Triggers for Gmail add-ons

    main

    ContextualTrigger defines conditions that fire when an opened email meets specific criteria. When a trigger fires, it executes a specified OnTriggerFunction to create cards and update the UI.

    Currently, the manifest supports:

    • Unconditional Trigger: An UnconditionalTrigger that executes the OnTriggerFunction whenever any email message is opened.
    // Example of an unconditional contextual trigger
    trigger := &gmail.ContextualTrigger{
        OnTriggerFunction: "myOnTriggerFunction",
        Trigger: &gmail.ContextualTrigger_Unconditional{
            Unconditional: &gmail.UnconditionalTrigger{},
        },
    }
  10. Data structures for Google Drive label fields (v2beta)

    main

    The field.proto definitions (implemented in Go) define the schema for Google Drive label fields in the v2beta API. These structures allow for the configuration of field properties, including text options, integer options, date options, and schema capabilities such as selection and user options.

    Key components of a field include:

    • TextOptions: Configuration for text-based fields, including min_length, max_length, and selection_options.
    • IntegerOptions: Configuration for integer-based fields, including min_value, max_value, and selection_options.
    • DateOptions: Configuration for date-based fields, including date_format and date_formattype.
    • SchemaCapabilities: Metadata describing what the field can do, such as can_update, can_delete, can_enable, can_search, and can_write.
    • Display Properties: Controls for how the field appears, such as display_name, display_hints, and lock_status.
  11. Google Drive Label Field message types (v2beta)

    main

    The google.apps.drive.labels.v2beta package provides message types for defining fields within Google Drive labels. The core Field message uses a oneof pattern to support different data types, including text, integers, dates, selections, and user-defined options.

    Key components of a Field include:

    • Type-specific options: TextOptions, IntegerOptions, DateOptions, SelectionOptions, and UserOptions.
    • Metadata and capabilities: Properties, DisplayHints, SchemaCapabilities, and AppliedCapabilities.
    • Lifecycle information: Lifecycle (tracking creators, updaters, and timestamps) and LockStatus.
    • Selection details: For selection-based fields, SelectionOptions contains a list of Choice objects, each with its own properties and display hints.
  12. Configure Cloud Pub/Sub notifications in Settings

    main

    To receive callback notifications, configure Settings_Notification with a CloudPubsubTopic destination.

    Setup Requirements: To register for notifications, the owner of the Pub/Sub topic must grant the following service account the projects.topics.publish permission: alerts-api-push-notifications@system.gserviceaccount.com

    Fields in Settings_Notification_CloudPubsubTopic:

    • topic_name (Required): The name of the Cloud Pub/Sub Topic.
    • payload_format (Optional): The format of the payload. If not specified, the format will be JSON. Uses the Settings_Notification_PayloadFormat enum.
    notification := &Settings_Notification{
    	Destination: &Settings_Notification_CloudPubsubTopic_{
    		CloudPubsubTopic: &Settings_Notification_CloudPubsubTopic{
    			TopicName:     "projects/my-project/topics/my-topic",
    			PayloadFormat: Settings_Notification_PAYLOAD_FORMAT_UNSPECIFIED,
    		},
    	},
    }