Chromium Code Reviews| Index: service/datastore/pls.go |
| diff --git a/service/datastore/pls.go b/service/datastore/pls.go |
| index 282f0834fb6336983f21edcebc7107760f4f9742..3a4f3bf1da519a2e1da4790dfbbb9d36c7c8c5b8 100644 |
| --- a/service/datastore/pls.go |
| +++ b/service/datastore/pls.go |
| @@ -125,6 +125,36 @@ import ( |
| // func (s *Special) Problem() error { |
| // return GetPLS(s).Problem() |
| // } |
| +// |
| +// Additionally, any field ptr-to-type may implement the PropertyConverter |
| +// interface to allow a single field to, for example, implement some alternate |
| +// encoding (json, gzip), or even just serialize to/from a simple string field. |
| +// This applies to normal fields, as well as metadata fields. It can be useful |
| +// for storing struct '$id's which have multi-field meanings. For example, the |
| +// Person struct below could be initialized in go as `&Person{Name{"Jane", |
| +// "Doe"}}`, retaining Jane's name as manipulable go fields. However, in the |
|
dnj
2015/11/03 03:11:25
nit: capitalize Go.
iannucci
2015/11/03 20:29:33
done
|
| +// datastore, it would have a key of `/Person,"Jane|Doe"`, and loading the |
| +// struct from the datastore as part of a Query, for example, would correct |
|
dnj
2015/11/03 03:11:25
nit: correctly*
iannucci
2015/11/03 20:29:33
done
|
| +// populate Person.Name.First and Person.Name.Last. |
| +// |
| +// type Name struct { |
| +// First string |
| +// Last string |
| +// } |
| +// |
| +// func (n *Name) ToProperty() (Property, error) { |
| +// return fmt.Sprintf("%s|%s", n.First, n.Last) |
| +// } |
| +// |
| +// func (n *Name) FromProperty(p Property) error { |
| +// // check p to be a PTString |
| +// // split on "|" |
| +// // assign to n.First, n.Last |
| +// } |
| +// |
| +// type Person struct { |
| +// Name `gae:"$id"` |
| +// } |
| func GetPLS(obj interface{}) interface { |
| PropertyLoadSaver |
| MetaGetterSetter |