google-cloudevents-go

module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2023 License: Apache-2.0

README

Google CloudEvents - Go

GoDoc Preview

This library provides Go types for Google CloudEvent data.

Features

  • Simple import and interface
  • Inline documentation for Go structs
  • Automatic decoding of base64 data
  • Enum support
  • Protobuf bindings

Installation

To install this package, run:

go get -u github.com/googleapis/google-cloudevents-go

This library requires Go 1.17+ and is tested with Go 1.19.

Usage

Unmarshal a CloudEvent data payload from raw bytes.

package examples

import (
	"fmt"
	"log"
	"time"

	"github.com/googleapis/google-cloudevents-go/cloud/storagedata"
	"google.golang.org/protobuf/encoding/protojson"
)

// cloudEventPayload is initialized with an example CloudEvent data payload.
// Source: github.com/googleapis/google-cloudevents/tree/main/examples/binary/storage/StorageObjectData-simple.json
var cloudEventPayload = []byte(`
{
	"bucket": "sample-bucket",
	"contentType": "text/plain",
	"crc32c": "rTVTeQ==",
	"etag": "CNHZkbuF/ugCEAE=",
	"generation": "1587627537231057",
	"id": "sample-bucket/folder/Test.cs/1587627537231057",
	"kind": "storage#object",
	"md5Hash": "kF8MuJ5+CTJxvyhHS1xzRg==",
	"mediaLink": "https://www.googleapis.com/download/storage/v1/b/sample-bucket/o/folder%2FTest.cs?generation=1587627537231057\u0026alt=media",
	"metageneration": "1",
	"name": "folder/Test.cs",
	"selfLink": "https://www.googleapis.com/storage/v1/b/sample-bucket/o/folder/Test.cs",
	"size": "352",
	"storageClass": "MULTI_REGIONAL",
	"timeCreated": "2020-04-23T07:38:57.230Z",
	"timeStorageClassUpdated": "2020-04-23T07:38:57.230Z",
	"updated": "2020-04-23T07:38:57.230Z"
}`)

func Example() {
	data := storagedata.StorageObjectData{}
	if err := protojson.Unmarshal(cloudEventPayload, &data); err != nil {
		log.Fatal("protojson.Unmarshal: ", err)
	}

	updated := data.Updated.AsTime().Format(time.UnixDate)
	fmt.Printf("Bucket: %s, Object: %s, Updated: %s", data.Bucket, data.Name, updated)

	// Output: Bucket: sample-bucket, Object: folder/Test.cs, Updated: Thu Apr 23 07:38:57 UTC 2020
}

Contributing

Contributions to this library are always welcome and highly encouraged.

See CONTRIBUTING for more information how to get started.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See Code of Conduct for more information.

Directories

Path Synopsis
cloud
apigatewaydata
Package apigatewaydata provides API Gateway type definitions for CloudEvent data payloads.
Package apigatewaydata provides API Gateway type definitions for CloudEvent data payloads.
apigeeregistrydata
Package apigeeregistrydata provides Apigee Registry type definitions for CloudEvent data payloads.
Package apigeeregistrydata provides Apigee Registry type definitions for CloudEvent data payloads.
auditdata
Package auditdata provides Cloud Audit Logs type definitions for CloudEvent data payloads.
Package auditdata provides Cloud Audit Logs type definitions for CloudEvent data payloads.
beyondcorp/appconnectionsdata
Package appconnectionsdata provides BeyondCorp type definitions for CloudEvent data payloads.
Package appconnectionsdata provides BeyondCorp type definitions for CloudEvent data payloads.
beyondcorp/appconnectorsdata
Package appconnectorsdata provides BeyondCorp type definitions for CloudEvent data payloads.
Package appconnectorsdata provides BeyondCorp type definitions for CloudEvent data payloads.
beyondcorp/appgatewaysdata
Package appgatewaysdata provides BeyondCorp type definitions for CloudEvent data payloads.
Package appgatewaysdata provides BeyondCorp type definitions for CloudEvent data payloads.
beyondcorp/clientconnectorservicesdata
Package clientconnectorservicesdata provides BeyondCorp type definitions for CloudEvent data payloads.
Package clientconnectorservicesdata provides BeyondCorp type definitions for CloudEvent data payloads.
beyondcorp/clientgatewaysdata
Package clientgatewaysdata provides BeyondCorp type definitions for CloudEvent data payloads.
Package clientgatewaysdata provides BeyondCorp type definitions for CloudEvent data payloads.
certificatemanagerdata
Package certificatemanagerdata provides Certificate Manager type definitions for CloudEvent data payloads.
Package certificatemanagerdata provides Certificate Manager type definitions for CloudEvent data payloads.
cloudbuilddata
Package cloudbuilddata provides Cloud Build type definitions for CloudEvent data payloads.
Package cloudbuilddata provides Cloud Build type definitions for CloudEvent data payloads.
clouddmsdata
Package clouddmsdata provides Database Migration type definitions for CloudEvent data payloads.
Package clouddmsdata provides Database Migration type definitions for CloudEvent data payloads.
datafusiondata
Package datafusiondata provides Cloud Data Fusion type definitions for CloudEvent data payloads.
Package datafusiondata provides Cloud Data Fusion type definitions for CloudEvent data payloads.
datastreamdata
Package datastreamdata provides Datastream type definitions for CloudEvent data payloads.
Package datastreamdata provides Datastream type definitions for CloudEvent data payloads.
eventarcdata
Package eventarcdata provides Eventarc type definitions for CloudEvent data payloads.
Package eventarcdata provides Eventarc type definitions for CloudEvent data payloads.
firestoredata
Package firestoredata provides Cloud Firestore type definitions for CloudEvent data payloads.
Package firestoredata provides Cloud Firestore type definitions for CloudEvent data payloads.
functionsdatav2
Package functionsdatav2 provides Cloud Functions type definitions for CloudEvent data payloads.
Package functionsdatav2 provides Cloud Functions type definitions for CloudEvent data payloads.
iotdata
Package iotdata provides Cloud IoT type definitions for CloudEvent data payloads.
Package iotdata provides Cloud IoT type definitions for CloudEvent data payloads.
memcachedata
Package memcachedata provides Cloud Memorystore for Memcached type definitions for CloudEvent data payloads.
Package memcachedata provides Cloud Memorystore for Memcached type definitions for CloudEvent data payloads.
schedulerdata
Package schedulerdata provides Cloud Scheduler type definitions for CloudEvent data payloads.
Package schedulerdata provides Cloud Scheduler type definitions for CloudEvent data payloads.
storagedata
Package storagedata provides Cloud Storage type definitions for CloudEvent data payloads.
Package storagedata provides Cloud Storage type definitions for CloudEvent data payloads.
workflowsdata
Package workflowsdata provides Workflows type definitions for CloudEvent data payloads.
Package workflowsdata provides Workflows type definitions for CloudEvent data payloads.
firebase
analyticsdata
Package analyticsdata provides Google Analytics for Firebase type definitions for CloudEvent data payloads.
Package analyticsdata provides Google Analytics for Firebase type definitions for CloudEvent data payloads.
authdata
Package authdata provides Firebase Authentication type definitions for CloudEvent data payloads.
Package authdata provides Firebase Authentication type definitions for CloudEvent data payloads.
databasedata
Package databasedata provides Firebase Realtime Database type definitions for CloudEvent data payloads.
Package databasedata provides Firebase Realtime Database type definitions for CloudEvent data payloads.
firebasealertsdata
Package firebasealertsdata provides Firebase Alerts type definitions for CloudEvent data payloads.
Package firebasealertsdata provides Firebase Alerts type definitions for CloudEvent data payloads.
remoteconfigdata
Package remoteconfigdata provides Firebase Remote Config type definitions for CloudEvent data payloads.
Package remoteconfigdata provides Firebase Remote Config type definitions for CloudEvent data payloads.
testlabdata
Package testlabdata provides Firebase Test Lab type definitions for CloudEvent data payloads.
Package testlabdata provides Firebase Test Lab type definitions for CloudEvent data payloads.
generators
internal
third_party

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL