@@ -10,7 +10,7 @@ import (
10
10
"fmt"
11
11
"reflect"
12
12
13
- "github.com/ golang/protobuf/proto"
13
+ "google. golang.org /protobuf/proto"
14
14
15
15
"google.golang.org/appengine"
16
16
"google.golang.org/appengine/internal"
@@ -48,6 +48,9 @@ func (e *ErrFieldMismatch) Error() string {
48
48
func protoToKey (r * pb.Reference ) (k * Key , err error ) {
49
49
appID := r .GetApp ()
50
50
namespace := r .GetNameSpace ()
51
+ if r .Path == nil {
52
+ return nil , fmt .Errorf ("path is empty: %w" , ErrInvalidKey )
53
+ }
51
54
for _ , e := range r .Path .Element {
52
55
k = & Key {
53
56
kind : e .GetType (),
@@ -74,11 +77,11 @@ func keyToProto(defaultAppID string, k *Key) *pb.Reference {
74
77
for i := k ; i != nil ; i = i .parent {
75
78
n ++
76
79
}
77
- e := make ([]* pb.Path_Element , n )
80
+ e := make ([]* pb.Path_ElementType , n )
78
81
for i := k ; i != nil ; i = i .parent {
79
82
n --
80
- e [n ] = & pb.Path_Element {
81
- Type : & i .kind ,
83
+ e [n ] = & pb.Path_ElementType {
84
+ Type : i .kind ,
82
85
}
83
86
// At most one of {Name,Id} should be set.
84
87
// Neither will be set for incomplete keys.
@@ -93,7 +96,7 @@ func keyToProto(defaultAppID string, k *Key) *pb.Reference {
93
96
namespace = proto .String (k .namespace )
94
97
}
95
98
return & pb.Reference {
96
- App : proto . String ( appID ) ,
99
+ App : appID ,
97
100
NameSpace : namespace ,
98
101
Path : & pb.Path {
99
102
Element : e ,
@@ -138,10 +141,10 @@ func multiValid(key []*Key) error {
138
141
139
142
// referenceValueToKey is the same as protoToKey except the input is a
140
143
// PropertyValue_ReferenceValue instead of a Reference.
141
- func referenceValueToKey (r * pb.PropertyValue_ReferenceValue ) (k * Key , err error ) {
144
+ func referenceValueToKey (r * pb.PropertyValue_ReferenceValueType ) (k * Key , err error ) {
142
145
appID := r .GetApp ()
143
146
namespace := r .GetNameSpace ()
144
- for _ , e := range r .Pathelement {
147
+ for _ , e := range r .PathElement {
145
148
k = & Key {
146
149
kind : e .GetType (),
147
150
stringID : e .GetName (),
@@ -159,20 +162,20 @@ func referenceValueToKey(r *pb.PropertyValue_ReferenceValue) (k *Key, err error)
159
162
160
163
// keyToReferenceValue is the same as keyToProto except the output is a
161
164
// PropertyValue_ReferenceValue instead of a Reference.
162
- func keyToReferenceValue (defaultAppID string , k * Key ) * pb.PropertyValue_ReferenceValue {
165
+ func keyToReferenceValue (defaultAppID string , k * Key ) * pb.PropertyValue_ReferenceValueType {
163
166
ref := keyToProto (defaultAppID , k )
164
- pe := make ([]* pb.PropertyValue_ReferenceValue_PathElement , len (ref .Path .Element ))
167
+ pe := make ([]* pb.PropertyValue_ReferenceValueType_PathElementType , len (ref .Path .Element ))
165
168
for i , e := range ref .Path .Element {
166
- pe [i ] = & pb.PropertyValue_ReferenceValue_PathElement {
169
+ pe [i ] = & pb.PropertyValue_ReferenceValueType_PathElementType {
167
170
Type : e .Type ,
168
171
Id : e .Id ,
169
172
Name : e .Name ,
170
173
}
171
174
}
172
- return & pb.PropertyValue_ReferenceValue {
175
+ return & pb.PropertyValue_ReferenceValueType {
173
176
App : ref .App ,
174
177
NameSpace : ref .NameSpace ,
175
- Pathelement : pe ,
178
+ PathElement : pe ,
176
179
}
177
180
}
178
181
0 commit comments