From 5797a5c3c2a0e35fd64fa2bb018b26ad707b87e7 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Wed, 17 Jun 2015 20:49:45 -0700 Subject: [PATCH] Add support for non-nullable nested messages. Nested messages with "[(gogoproto.nullable) = false]" option are generated as structs, rather than pointers to structs. Add support for such struct values to populate parameter functionality. Add test case. Resolves #20. --- runtime/query.go | 3 +++ runtime/query_test.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/runtime/query.go b/runtime/query.go index 2ede4735754..63ce09278aa 100644 --- a/runtime/query.go +++ b/runtime/query.go @@ -59,6 +59,9 @@ func populateQueryParameter(msg proto.Message, fieldPath []string, values []stri } m = f.Elem() continue + case reflect.Struct: + m = f + continue default: return fmt.Errorf("unexpected type %s in %T", f.Type(), msg) } diff --git a/runtime/query_test.go b/runtime/query_test.go index 5c238d53540..1dc4a990633 100644 --- a/runtime/query_test.go +++ b/runtime/query_test.go @@ -71,6 +71,7 @@ func TestPopulateParameters(t *testing.T) { "nested.nested.nested.string_value": {"s"}, "nested.nested.string_value": {"t"}, "nested.string_value": {"u"}, + "nested_non_null.string_value": {"v"}, }, filter: internal.NewDoubleArray(nil), want: &proto3Message{ @@ -84,6 +85,9 @@ func TestPopulateParameters(t *testing.T) { }, StringValue: proto.String("u"), }, + NestedNonNull: proto2Message{ + StringValue: proto.String("v"), + }, }, }, { @@ -195,6 +199,7 @@ func TestPopulateParametersWithFilters(t *testing.T) { type proto3Message struct { Nested *proto2Message `protobuf:"bytes,1,opt,name=nested" json:"nested,omitempty"` + NestedNonNull proto2Message `protobuf:"bytes,11,opt,name=nested_non_null" json:"nested_non_null,omitempty"` FloatValue float32 `protobuf:"fixed32,2,opt,name=float_value" json:"float_value,omitempty"` DoubleValue float64 `protobuf:"fixed64,3,opt,name=double_value" json:"double_value,omitempty"` Int64Value int64 `protobuf:"varint,4,opt,name=int64_value" json:"int64_value,omitempty"`