| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package datastore | 5 package datastore |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "reflect" | 8 "reflect" |
| 9 ) | 9 ) |
| 10 | 10 |
| 11 // GetPLS resolves obj into a PropertyLoadSaver. | 11 // GetPLS resolves obj into a PropertyLoadSaver. |
| 12 // | 12 // |
| 13 // obj must be a non-nil pointer to a struct of some sort. | 13 // obj must be a non-nil pointer to a struct of some sort. |
| 14 // | 14 // |
| 15 // By default, exported fields will be serialized to/from the datastore. If the | 15 // By default, exported fields will be serialized to/from the datastore. If the |
| 16 // field is not exported, it will be skipped by the serialization routines. | 16 // field is not exported, it will be skipped by the serialization routines. |
| 17 // | 17 // |
| 18 // If a field is of a non-supported type (see Property for the list of supported | 18 // If a field is of a non-supported type (see Property for the list of supported |
| 19 // property types), the resulting PropertyLoadSaver will have a non-nil | 19 // property types), the resulting PropertyLoadSaver will have a non-nil |
| 20 // Problem(). Other problems include duplicate field names (due to tagging), | 20 // Problem(). Other problems include duplicate field names (due to tagging), |
| 21 // recursively defined structs, nested structures with multiple slices (e.g. | 21 // recursively defined structs, nested structures with multiple slices (e.g. |
| 22 // slices of slices, either directly `[][]type` or indirectly `[]Embedded` where | 22 // slices of slices, either directly `[][]type` or indirectly `[]Embedded` where |
| 23 // Embedded contains a slice.) | 23 // Embedded contains a slice.) |
| 24 // | 24 // |
| 25 // GetPLS supports the following struct tag syntax: | 25 // GetPLS supports the following struct tag syntax: |
| 26 // `gae:"fieldName[,noindex]"` -- an alternate fieldname for an exportable | 26 // `gae:"fieldName[,noindex]"` -- an alternate fieldname for an exportable |
| 27 //» field. When the struct is serialized or deserialized, fieldName wil
l be | 27 // field. When the struct is serialized or deserialized, fieldName will be |
| 28 // associated with the struct field instead of the field's Go name. This is | 28 // associated with the struct field instead of the field's Go name. This is |
| 29 // useful when writing Go code which interfaces with appengine code written | 29 // useful when writing Go code which interfaces with appengine code written |
| 30 // in other languages (like python) which use lowercase as their default | 30 // in other languages (like python) which use lowercase as their default |
| 31 //» » datastore field names. | 31 // datastore field names. |
| 32 // | 32 // |
| 33 // A fieldName of "-" means that gae will ignore the field for all | 33 // A fieldName of "-" means that gae will ignore the field for all |
| 34 // serialization/deserialization. | 34 // serialization/deserialization. |
| 35 // | 35 // |
| 36 // if noindex is specified, then this field will not be indexed in the | 36 // if noindex is specified, then this field will not be indexed in the |
| 37 // datastore, even if it was an otherwise indexable type. If fieldName is | 37 // datastore, even if it was an otherwise indexable type. If fieldName is |
| 38 // blank, and noindex is specifed, then fieldName will default to the | 38 // blank, and noindex is specifed, then fieldName will default to the |
| 39 // field's actual name. Note that by default, all fields (with indexable | 39 // field's actual name. Note that by default, all fields (with indexable |
| 40 // types) are indexed. | 40 // types) are indexed. |
| 41 // | 41 // |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 c, ok := structCodecs[structType] | 104 c, ok := structCodecs[structType] |
| 105 structCodecsMutex.RUnlock() | 105 structCodecsMutex.RUnlock() |
| 106 if ok { | 106 if ok { |
| 107 return c | 107 return c |
| 108 } | 108 } |
| 109 | 109 |
| 110 structCodecsMutex.Lock() | 110 structCodecsMutex.Lock() |
| 111 defer structCodecsMutex.Unlock() | 111 defer structCodecsMutex.Unlock() |
| 112 return getStructCodecLocked(structType) | 112 return getStructCodecLocked(structType) |
| 113 } | 113 } |
| OLD | NEW |