Comments (3)
Hi @namnhatdoan, I don't believe you can use this library with Cloud functions 1st gen. Go experts @grayside and @muncus may have a work around for this use case. I recommend looking at sample and tutorial, https://cloud.google.com/functions/docs/tutorials/storage, that use Cloud Functions 2nd gen to parse StorageObjectData from a CloudEvent.
from google-cloudevents-go.
Thank you @namnhatdoan for opening this issue with detailed logs.
As @averikitsch said. You will note the linked tutorial uses --trigger-event-filters="type=google.cloud.storage.object.v1.finalized"
and also shows how CloudEvent functions are given an Event object, which is then used to explicitly unmarshal data using this library inside the function implementation.
For a broader introduction to CloudEvent functions, see https://cloud.google.com/functions/docs/writing/write-event-driven-functions
Please reopen this issue if there is a further concern about library behavior.
from google-cloudevents-go.
Hi, Thank you for your reply and sorry for my late response. This is just an update from my side and share my work around if some one want to do the same thing.
My team decided to not upgrade to 2nd gen gcloud functions for now so we continued to do it with 1st gen. I worked around for this case by creating another struct that inherit from this and modify it a little bit
- For int fields, add "string" into json annotation. eg: from
json:"generation,omitempty"
tojson:"generation,string,omitempty"
- For timestamp fields, using time.Time instead.
Something like this
type StorageObjectData struct { *storagedata.StorageObjectData Name string
protobuf:"bytes,23,opt,name=name,proto3" json:"name,omitempty"Id string
protobuf:"bytes,24,opt,name=id,proto3" json:"id,omitempty"`
Generation int64 `protobuf:"varint,26,opt,name=generation,proto3" json:"generation,string,omitempty"`
Metageneration int64 `protobuf:"varint,6,opt,name=metageneration,proto3" json:"metageneration,string,omitempty"`
Size int64 `protobuf:"varint,9,opt,name=size,proto3" json:"size,string,omitempty"`
ComponentCount int32 `protobuf:"varint,12,opt,name=component_count,json=componentCount,proto3" json:"component_count,string,omitempty"`
TimeCreated time.Time `protobuf:"bytes,10,opt,name=time_created,json=timeCreated,proto3" json:"time_created,omitempty"`
TimeDeleted time.Time `protobuf:"bytes,7,opt,name=time_deleted,json=timeDeleted,proto3" json:"time_deleted,omitempty"`
Updated time.Time `protobuf:"bytes,15,opt,name=updated,proto3" json:"updated,omitempty"`
TimeStorageClassUpdated time.Time `protobuf:"bytes,18,opt,name=time_storage_class_updated,json=timeStorageClassUpdated,proto3" json:"time_storage_class_updated,omitempty"`
RetentionExpirationTime time.Time `protobuf:"bytes,20,opt,name=retention_expiration_time,json=retentionExpirationTime,proto3" json:"retention_expiration_time,omitempty"`
}`
For my real use case, I actually just declare some fields that need to be handled instead of support all fields like this.
Thanks
from google-cloudevents-go.
Related Issues (20)
- json: invalid use of ,string struct tag, trying to unmarshal unquoted value into *int64 HOT 1
- [Policy Bot] found one or more issues with this repository.
- [Policy Bot] found one or more issues with this repository. HOT 1
- Improve error reporting in protoc-gen-go-googlecetypes
- Evaluate replacement of realpath with string concatenation
- Add YAML Linting to validate changes to workflows
- Add support for Pub/Sub HOT 1
- generator: Version string munging cannot handle dataflow's v1beta3
- process: slow down generator re-runs
- Add protobuf example & README documentation
- Library generation failed (dd2ac79) HOT 1
- Add json hints for unmarshal types like int64 HOT 1
- Library generation failed (8b0df4f)
- Library generation failed (8b0df4f)
- Library generation failed (8b0df4f)
- Library generation failed (8b0df4f)
- Library generation failed (8b0df4f)
- Library generation failed (8b0df4f)
- Library generation failed (8b0df4f)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-cloudevents-go.