go: cloud.google.com/go/functions/metadata Index | Files

package metadata

import "cloud.google.com/go/functions/metadata"

Package metadata provides methods for creating and accessing context.Context objects with Google Cloud Functions metadata.

NOTE: This package is in alpha. It is not stable, and is likely to change.


Package Files

doc.go metadata.go

func NewContext Uses

func NewContext(ctx context.Context, m *Metadata) context.Context

NewContext returns a new Context carrying m. If m is nil, NewContext returns ctx. NewContext is only used for writing tests which rely on Metadata.

type Metadata Uses

type Metadata struct {
    // EventID is a unique ID for the event. For example: "70172329041928".
    EventID string `json:"eventId"`
    // Timestamp is the date/time this event was created.
    Timestamp time.Time `json:"timestamp"`
    // EventType is the type of the event. For example: "google.pubsub.topic.publish".
    EventType string `json:"eventType"`
    // Resource is the resource that triggered the event.
    Resource *Resource `json:"resource"`

Metadata holds Google Cloud Functions metadata.

func FromContext Uses

func FromContext(ctx context.Context) (*Metadata, error)

FromContext extracts the Metadata from the Context, if present.

type Resource Uses

type Resource struct {
    // Service is the service that triggered the event.
    Service string `json:"service"`
    // Name is the name associated with the event.
    Name string `json:"name"`
    // Type is the type of event.
    Type string `json:"type"`
    // Path is the path to the resource type (deprecated).
    // This is the case for some deprecated GCS
    // notifications, which populate the resource field as a string containing the topic
    // rather than as the expected dictionary.
    // See the Attributes section of https://cloud.google.com/storage/docs/pubsub-notifications
    // for more details.
    RawPath string `json:"-"`

Resource holds Google Cloud Functions resource metadata. Resource values are dependent on the event type they're from.

func (*Resource) UnmarshalJSON Uses

func (r *Resource) UnmarshalJSON(data []byte) error

UnmarshalJSON specializes the Resource unmarshalling to handle the case where the value is a string instead of a map. See the comment above on RawPath for why this needs to be handled.

Package metadata imports 5 packages (graph) and is imported by 11 packages. Updated 2020-06-10. Refresh now. Tools for package owners.