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.
Metadata
typeMetadatastruct{// EventID is a unique ID for the event. For example: "70172329041928".EventIDstring`json:"eventId"`// Timestamp is the date/time this event was created.Timestamptime.Time`json:"timestamp"`// EventType is the type of the event. For example: "google.pubsub.topic.publish".EventTypestring`json:"eventType"`// Resource is the resource that triggered the event.Resource*Resource`json:"resource"`}
FromContext extracts the Metadata from the Context, if present.
Resource
typeResourcestruct{// Service is the service that triggered the event.Servicestring`json:"service"`// Name is the name associated with the event.Namestring`json:"name"`// Type is the type of event.Typestring`json:"type"`// RawPath is the path to the resource type (deprecated).// It is used by the GCS notifications shown in// https://cloud.google.com/storage/docs/pubsub-notifications,// which populate the resource field as a string containing the topic// rather than as the expected dictionary.// It is also used when triggering Cloud Functions by [Firebase Realtime Database// Triggers](https://cloud.google.com/functions/docs/calling/realtime-data).RawPathstring`json:"-"`}
Resource holds Google Cloud Functions resource metadata.
Resource values are dependent on the event type they're from.
MarshalJSON specializes the Resource marshalling 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.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe latest version of the Google Cloud Functions metadata package is 1.19.4, and numerous previous versions are also available for use.\u003c/p\u003e\n"],["\u003cp\u003eThis package is currently in alpha, meaning it is not yet stable and is subject to change, potentially with breaking changes.\u003c/p\u003e\n"],["\u003cp\u003eThe package provides methods for creating and accessing context objects with Google Cloud Functions metadata, including unique event IDs, timestamps, event types, and resource information.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eMetadata\u003c/code\u003e type contains fields for \u003ccode\u003eEventID\u003c/code\u003e, \u003ccode\u003eTimestamp\u003c/code\u003e, \u003ccode\u003eEventType\u003c/code\u003e, and \u003ccode\u003eResource\u003c/code\u003e, offering comprehensive details about the event.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eResource\u003c/code\u003e type includes fields like \u003ccode\u003eService\u003c/code\u003e, \u003ccode\u003eName\u003c/code\u003e, \u003ccode\u003eType\u003c/code\u003e, and a deprecated \u003ccode\u003eRawPath\u003c/code\u003e for managing event triggers and resource details.\u003c/p\u003e\n"]]],[],null,["# Cloud Functions - Package cloud.google.com/go/functions/metadata (v1.19.6)\n\nVersion latestkeyboard_arrow_down\n\n- [1.19.6 (latest)](/go/docs/reference/cloud.google.com/go/functions/latest/metadata)\n- [1.19.5](/go/docs/reference/cloud.google.com/go/functions/1.19.5/metadata)\n- [1.18.0](/go/docs/reference/cloud.google.com/go/functions/1.18.0/metadata)\n- [1.17.0](/go/docs/reference/cloud.google.com/go/functions/1.17.0/metadata)\n- [1.16.6](/go/docs/reference/cloud.google.com/go/functions/1.16.6/metadata)\n- [1.15.4](/go/docs/reference/cloud.google.com/go/functions/1.15.4/metadata)\n- [1.14.0](/go/docs/reference/cloud.google.com/go/functions/1.14.0/metadata)\n- [1.13.1](/go/docs/reference/cloud.google.com/go/functions/1.13.1/metadata)\n- [1.12.0](/go/docs/reference/cloud.google.com/go/functions/1.12.0/metadata)\n- [1.11.0](/go/docs/reference/cloud.google.com/go/functions/1.11.0/metadata)\n- [1.10.0](/go/docs/reference/cloud.google.com/go/functions/1.10.0/metadata)\n- [1.9.0](/go/docs/reference/cloud.google.com/go/functions/1.9.0/metadata)\n- [1.8.0](/go/docs/reference/cloud.google.com/go/functions/1.8.0/metadata)\n- [1.7.0](/go/docs/reference/cloud.google.com/go/functions/1.7.0/metadata)\n- [1.6.0](/go/docs/reference/cloud.google.com/go/functions/1.6.0/metadata)\n- [1.5.0](/go/docs/reference/cloud.google.com/go/functions/1.5.0/metadata)\n- [1.4.0](/go/docs/reference/cloud.google.com/go/functions/1.4.0/metadata)\n- [1.3.0](/go/docs/reference/cloud.google.com/go/functions/1.3.0/metadata)\n- [1.2.0](/go/docs/reference/cloud.google.com/go/functions/1.2.0/metadata)\n- [1.1.0](/go/docs/reference/cloud.google.com/go/functions/1.1.0/metadata)\n- [1.0.0](/go/docs/reference/cloud.google.com/go/functions/1.0.0/metadata)\n- [0.2.0](/go/docs/reference/cloud.google.com/go/functions/0.2.0/metadata)\n- [0.1.0](/go/docs/reference/cloud.google.com/go/functions/0.1.0/metadata) \n| **Alpha**\n|\n|\n| This library is covered by the [Pre-GA Offerings Terms](/terms/service-terms#1)\n| of the Terms of Service. Pre-GA libraries might have limited support,\n| and changes to pre-GA libraries might not be compatible with other pre-GA versions.\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n**Note:** To get more information about this package, such as access to older versions, view [this package on pkg.go.dev](https://pkg.go.dev/cloud.google.com/go/functions/metadata). \n\u003cbr /\u003e\n\nPackage metadata provides methods for creating and accessing context.Context\nobjects with Google Cloud Functions metadata.\n\nNOTE: This package is in alpha. It is not stable, and is likely to change. \n\nFunctions\n---------\n\n### func NewContext\n\n func NewContext(ctx https://pkg.go.dev/context.https://pkg.go.dev/context#Context, m *#cloud_google_com_go_functions_metadata_Metadata) https://pkg.go.dev/context.https://pkg.go.dev/context#Context\n\nNewContext returns a new Context carrying m. If m is nil, NewContext returns\nctx. NewContext is only used for writing tests which rely on Metadata. \n\nMetadata\n--------\n\n type Metadata struct {\n \t// EventID is a unique ID for the event. For example: \"70172329041928\".\n \tEventID https://pkg.go.dev/builtin#string `json:\"eventId\"`\n \t// Timestamp is the date/time this event was created.\n \tTimestamp https://pkg.go.dev/time.https://pkg.go.dev/time#Time `json:\"timestamp\"`\n \t// EventType is the type of the event. For example: \"google.pubsub.topic.publish\".\n \tEventType https://pkg.go.dev/builtin#string `json:\"eventType\"`\n \t// Resource is the resource that triggered the event.\n \tResource *#cloud_google_com_go_functions_metadata_Resource `json:\"resource\"`\n }\n\nMetadata holds Google Cloud Functions metadata. \n\n### func FromContext\n\n func FromContext(ctx https://pkg.go.dev/context.https://pkg.go.dev/context#Context) (*#cloud_google_com_go_functions_metadata_Metadata, https://pkg.go.dev/builtin#error)\n\nFromContext extracts the Metadata from the Context, if present. \n\nResource\n--------\n\n type Resource struct {\n \t// Service is the service that triggered the event.\n \tService https://pkg.go.dev/builtin#string `json:\"service\"`\n \t// Name is the name associated with the event.\n \tName https://pkg.go.dev/builtin#string `json:\"name\"`\n \t// Type is the type of event.\n \tType https://pkg.go.dev/builtin#string `json:\"type\"`\n \t// RawPath is the path to the resource type (deprecated).\n \t// It is used by the GCS notifications shown in\n \t// https://cloud.google.com/storage/docs/pubsub-notifications,\n \t// which populate the resource field as a string containing the topic\n \t// rather than as the expected dictionary.\n \t// It is also used when triggering Cloud Functions by [Firebase Realtime Database\n \t// Triggers](https://cloud.google.com/functions/docs/calling/realtime-data).\n \tRawPath https://pkg.go.dev/builtin#string `json:\"-\"`\n }\n\nResource holds Google Cloud Functions resource metadata.\nResource values are dependent on the event type they're from. \n\n### func (\\*Resource) MarshalJSON\n\n func (r *#cloud_google_com_go_functions_metadata_Resource) MarshalJSON() ([]https://pkg.go.dev/builtin#byte, https://pkg.go.dev/builtin#error)\n\nMarshalJSON specializes the Resource marshalling to handle the case where the\nvalue is a string instead of a map. See the comment above on RawPath for why this\nneeds to be handled. \n\n### func (\\*Resource) UnmarshalJSON\n\n func (r *#cloud_google_com_go_functions_metadata_Resource) UnmarshalJSON(data []https://pkg.go.dev/builtin#byte) https://pkg.go.dev/builtin#error\n\nUnmarshalJSON specializes the Resource unmarshalling to handle the case where the\nvalue is a string instead of a map. See the comment above on RawPath for why this\nneeds to be handled."]]