Giter Site home page Giter Site logo

Comments (3)

averikitsch avatar averikitsch commented on June 20, 2024

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.

grayside avatar grayside commented on June 20, 2024

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.

namnhatdoan avatar namnhatdoan commented on June 20, 2024

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" to json:"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 stringprotobuf:"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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.