Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Side by Side Diff: service/datastore/pls.go

Issue 1401533007: Add ability to override just the metadata in a struct. (Closed) Base URL: https://github.com/luci/gae.git@add_exists_method
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | service/datastore/pls_impl.go » ('j') | service/datastore/pls_impl.go » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // struct Comment { 79 // struct Comment {
80 // ID int64 `gae:"$id"` 80 // ID int64 `gae:"$id"`
81 // // "kind" is automatically implied by the struct name: "Comment" 81 // // "kind" is automatically implied by the struct name: "Comment"
82 // 82 //
83 // // Parent will be enforced by the application to be a User key. 83 // // Parent will be enforced by the application to be a User key.
84 // Parent Key `gae:"$parent"` 84 // Parent Key `gae:"$parent"`
85 // 85 //
86 // // 'Lines' will serialized to the datastore in the field 'Lines' 86 // // 'Lines' will serialized to the datastore in the field 'Lines'
87 // Lines []string 87 // Lines []string
88 // } 88 // }
89 //
90 // A pointer-to-struct may also implement MetaGetterSetter to provide more
91 // sophistocated metadata values.
Vadim Sh. 2015/10/13 04:27:48 note that explicitly defined fields take precedenc
iannucci 2015/10/13 04:34:40 Done.
89 func GetPLS(obj interface{}) PropertyLoadSaver { 92 func GetPLS(obj interface{}) PropertyLoadSaver {
90 v := reflect.ValueOf(obj) 93 v := reflect.ValueOf(obj)
91 if v.Kind() != reflect.Ptr || v.Elem().Kind() != reflect.Struct { 94 if v.Kind() != reflect.Ptr || v.Elem().Kind() != reflect.Struct {
92 return &structPLS{c: &structCodec{problem: ErrInvalidEntityType} } 95 return &structPLS{c: &structCodec{problem: ErrInvalidEntityType} }
93 } 96 }
94 if v.IsNil() { 97 if v.IsNil() {
95 return &structPLS{c: &structCodec{problem: ErrInvalidEntityType} } 98 return &structPLS{c: &structCodec{problem: ErrInvalidEntityType} }
96 } 99 }
97 v = v.Elem() 100 v = v.Elem()
98 c := getCodec(v.Type()) 101 c := getCodec(v.Type())
99 return &structPLS{v, c} 102 return &structPLS{v, c}
100 } 103 }
101 104
102 func getCodec(structType reflect.Type) *structCodec { 105 func getCodec(structType reflect.Type) *structCodec {
103 structCodecsMutex.RLock() 106 structCodecsMutex.RLock()
104 c, ok := structCodecs[structType] 107 c, ok := structCodecs[structType]
105 structCodecsMutex.RUnlock() 108 structCodecsMutex.RUnlock()
106 if ok { 109 if ok {
107 return c 110 return c
108 } 111 }
109 112
110 structCodecsMutex.Lock() 113 structCodecsMutex.Lock()
111 defer structCodecsMutex.Unlock() 114 defer structCodecsMutex.Unlock()
112 return getStructCodecLocked(structType) 115 return getStructCodecLocked(structType)
113 } 116 }
OLDNEW
« no previous file with comments | « no previous file | service/datastore/pls_impl.go » ('j') | service/datastore/pls_impl.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698