type Bar struct {
X, Y int64
}
type Foo struct {
Additional map[string]string
Bar []Bar
}
func (f *Foo) Load(c <-chan datastore.Property) error {
for p := range c {
if strings.HasPrefix(p.Name, "Additional.") {
f.Additional[p.Name[11:]] = string(p.Value)
}
}
return nil
}
func (f *Foo) Save(c chan<- datastore.Property) error {
defer close(c)
for key, val :=range f.Additional {
c <- datastore.Property{
Name: "Additional."+key,
Value: val,
}
}
return nil
}
Cool! I am glad you found the answer.
If you wouldn't mind sharing an updated example on this list, that would be great.
Thanks!
--
You received this message because you are subscribed to the Google Groups "google-appengine-go" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengin...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
func (f *Foo) Load(c <-chan datastore.Property) error {
f.Additional = make(map[string]string)
f.Bar = make([]Bar, 0, 2) // somehow to know the length?
countBar := 0
for p := range c {
if strings.HasPrefix(p.Name, "Additional.") {
f.Additional[p.Name[11:]] = p.Value.(string)
} else if p.Name == "Bar.X" {
f.Bar = append(f.Bar, Bar{X: p.Value.(int64)})
} else if p.Name == "Bar.Y" {
f.Bar[countBar].Y = p.Value.(int64)
countBar++
}
}
return nil
}
func (f *Foo) Save(c chan<- datastore.Property) error {
defer close(c)
for i := 0; i < len(f.Bar); i++ {
c <- datastore.Property{
Name: "Bar.X",
Value: int64(f.Bar[i].X),
Multiple: true,
}
c <- datastore.Property{
Name: "Bar.Y",
Value: int64(f.Bar[i].Y),
Multiple: true,
}
}
for key, val := range f.Additional {
c <- datastore.Property{
Name: "Additional." + key,
Value: val,
}
}