Created
December 8, 2012 21:31
-
-
Save arturovm/4242053 to your computer and use it in GitHub Desktop.
This is a re-implementation of the GAE Go runtime Map type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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