Skip to content

Instantly share code, notes, and snippets.

@feloy
Created January 19, 2019 13:07
Show Gist options
  • Save feloy/99afe3bbd8e359f9d7b071982d3ad6f5 to your computer and use it in GitHub Desktop.
Save feloy/99afe3bbd8e359f9d7b071982d3ad6f5 to your computer and use it in GitHub Desktop.
package p
// Score represents the Score collection in Firestore
type Score struct {
Uid string
Name string
Points int
Details string
Country string
}
// NewFromFirestoreValue returns a new Score, from values in FirestoreValue
func NewFromFirestoreValue(v FirestoreValue) (*Score, error) {
var score Score
uid, err := v.getStringValue("uid")
if err != nil {
return nil, err
}
name, err := v.getStringValue("name")
if err != nil {
return nil, err
}
points, err := v.getIntegerValue("points")
if err != nil {
return nil, err
}
details, err := v.getStringValue("details")
if err != nil {
return nil, err
}
country, err := v.getStringValue("country")
if err != nil {
return nil, err
}
score = Score{
Uid: uid,
Name: name,
Points: points,
Details: details,
Country: country,
}
return &score, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment