zevdg / fcf Goto Github PK
View Code? Open in Web Editor NEWHelper library for Google Cloud Functions' firestore triggers in Go
License: MIT License
Helper library for Google Cloud Functions' firestore triggers in Go
License: MIT License
I'm having a bit of trouble figuring out the right way to setup my types to pick up this structure.
On my server this is the natural type:
// Assessment stores assessment in db
type Assessment struct {
TemplateID string `firestore:"templateID"`
Created time.Time `firestore:"created"`
UserID string `firestore:"userID"`
Slots map[string]*bot.Slot `firestore:"slots"`
}
type Slot struct {
Value interface{} `firestore:"value"`
Created time.Time `firestore:"created"`
}
Which then gets sent as this to the firestore trigger cloud function:
{
"oldValue": {},
"updateMask": {},
"value": {
"createTime": "2019-06-13T22:44:02.081775Z",
"fields": {
"created": {
"timestampValue": "2019-06-13T22:44:01.926976Z"
},
"slots": {
"mapValue": {
"fields": {
"frustrated": {
"mapValue": {
"fields": {
"created": {
"timestampValue": "2019-06-13T22:43:57.332848Z"
},
"value": {
"stringValue": "zxc"
}
}
}
},
"hitQuota": {
"mapValue": {
"fields": {
"created": {
"timestampValue": "2019-06-13T22:43:53.571678Z"
},
"value": {
"stringValue": "qwe"
}
}
}
},
"toolsTechnology": {
"mapValue": {
"fields": {
"created": {
"timestampValue": "2019-06-13T22:43:55.566685Z"
},
"value": {
"stringValue": "asd"
}
}
}
}
}
}
},
"templateID": {
"stringValue": "ae"
},
"userID": {
"stringValue": "1667237206656764"
}
},
"name": "removed",
"updateTime": "2019-06-13T22:44:02.081775Z"
}
}
The goal is to iterate over every slot easily and grab that value. That's where I'm having the most trouble. I'm close but... feel like I may be doing it wrong and missing something from a mental model perspective.
Here's the type on the cloud function
type assessmentData struct {
TemplateID string `fcf:"templateID"`
Created time.Time `fcf:"created"`
UserID string `fcf:"userID"`
MapVal map[string]struct {
ValString map[string]string `json:"stringValue"`
} `fcf:"slots"`
MapDynamic map[string]interface{} `fcf:"slots"`
MapInterface interface{} `fcf:"slots"`
}
I'm experimenting so there's the superfluous last two attributes.
Basically just want to output each value in slot as finishing my experiment.
for k, v := range a.MapVal {
log.Printf("MapVal: k: %s, val: %+v", k, v)
log.Printf("MapVal: v : %+v", v)
for kk, vv := range v.ValString { // this would be the slot attributes
log.Printf("ValString: kk: %s, val: %+v", kk, vv)
log.Printf("ValString: vv: %+v", vv)
}
}
I tried it without having the nested struct with ValString but wasn't having much luck there so trying to do this piece more manually but still close but no cigar.
Anyway, thanks!
edit: note:
Usually I'd expect to just use a map[string]type
structure for dynamic keys but this is proving difficult with the payload - want to simplify if possible.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.