- 0.116.0 (latest)
- 0.115.1
- 0.114.0
- 0.113.0
- 0.112.2
- 0.111.0
- 0.110.10
- 0.109.0
- 0.108.0
- 0.107.0
- 0.106.0
- 0.105.0
- 0.104.0
- 0.103.0
- 0.102.1
- 0.101.1
- 0.100.2
- 0.99.0
- 0.98.0
- 0.97.0
- 0.96.0
- 0.95.0
- 0.94.1
- 0.93.3
- 0.92.3
- 0.91.1
- 0.90.0
- 0.89.0
- 0.88.0
- 0.87.0
- 0.86.0
- 0.85.0
- 0.84.0
- 0.83.0
- 0.82.0
- 0.81.0
- 0.80.0
- 0.79.0
- 0.78.0
- 0.77.0
- 0.76.0
- 0.75.0
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.
Functions
func NewContext
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
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
FromContext extracts the Metadata from the Context, if present.
Resource
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) MarshalJSON
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.
func (*Resource) UnmarshalJSON
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.