GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - googleapis/google-cloudevents-go: CloudEvent Types for Go

BranchesTags
Open more actions menu

Latest commit

 

History

172 Commits
172 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
cloud
cloud
 
 
examples
examples
 
 
firebase
firebase
 
 
generators
generators
 
 
internal/testhelper
internal/testhelper
 
 
third_party/googleapis/google/api
third_party/googleapis/google/api
 
 
tools
tools
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 
generate-code.sh
generate-code.sh
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
renovate.json
renovate.json
 
 

Repository files navigation

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 you omit `DiscardUnknown`, protojson.Unmarshal returns an error
	// when encountering a new or unknown field.
	options := protojson.UnmarshalOptions{
		DiscardUnknown: true,
	}
	if err := options.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.

About

CloudEvent Types for Go

Topics

eventarcgolangpreviewtype-definitions

Resources

Readme
Apache-2.0 license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

32 stars

Watchers

40 watching

Forks

8 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.