Skip to content

Instantly share code, notes, and snippets.

@arturovm
Created December 8, 2012 21:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arturovm/4242053 to your computer and use it in GitHub Desktop.
Save arturovm/4242053 to your computer and use it in GitHub Desktop.
This is a re-implementation of the GAE Go runtime Map type.
package main
import (
"reflect"
"appengine"
"appengine/datastore"
)
// define Map
type Map map[string]interface{}
func (m Map) Load(c <-chan datastore.Property) error {
for p := range c {
if p.Multiple {
value := reflect.ValueOf(m[p.Name])
if value.Kind() != reflect.Slice {
m[p.Name] = []interface{}{p.Value}
} else {
m[p.Name] = append(m[p.Name].([]interface{}), p.Value)
}
} else {
m[p.Name] = p.Value
}
}
return nil
}
func (m Map) Save(c chan<- datastore.Property) error {
defer close(c)
for k, v := range m {
c <- datastore.Property {
Name: k,
Value: v,
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment