https://github.com/googleapis/google-cloudevents-go
CloudEvent Types for Go
https://github.com/googleapis/google-cloudevents-go
eventarc golang preview type-definitions
Last synced: 11 months ago
JSON representation
CloudEvent Types for Go
- Host: GitHub
- URL: https://github.com/googleapis/google-cloudevents-go
- Owner: googleapis
- License: apache-2.0
- Created: 2020-06-17T18:33:44.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2025-06-27T20:22:06.000Z (12 months ago)
- Last Synced: 2025-06-27T21:18:58.883Z (12 months ago)
- Topics: eventarc, golang, preview, type-definitions
- Language: Go
- Homepage:
- Size: 4.65 MB
- Stars: 27
- Watchers: 44
- Forks: 7
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# Google CloudEvents - Go
[](https://pkg.go.dev/mod/github.com/googleapis/google-cloudevents-go) [](https://cloud.google.com/products#section-22)
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:
``` sh
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.
```golang
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](./CONTRIBUTING.md) 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.