-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: grpc-transcode plugin: fix map data population #8731
Changes from 9 commits
4cc4bbe
3f1246f
f21a730
6180cc7
9751ae5
7b5786e
30655f8
2a45eda
a032090
58f3b4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,6 +22,7 @@ local ngx = ngx | |||||
local string = string | ||||||
local table = table | ||||||
local ipairs = ipairs | ||||||
local pairs = pairs | ||||||
local tonumber = tonumber | ||||||
local type = type | ||||||
|
||||||
|
@@ -131,7 +132,7 @@ local function get_from_request(request_table, name, kind) | |||||
end | ||||||
|
||||||
|
||||||
function _M.map_message(field, default_values, request_table) | ||||||
function _M.map_message(field, default_values, request_table, real_key) | ||||||
if not pb.type(field) then | ||||||
return nil, "Field " .. field .. " is not defined" | ||||||
end | ||||||
|
@@ -164,15 +165,33 @@ function _M.map_message(field, default_values, request_table) | |||||
end | ||||||
sub = sub_array | ||||||
else | ||||||
sub, err = _M.map_message(field_type, default_values and default_values[name], | ||||||
request_table[name]) | ||||||
if ty == "map" then | ||||||
local tbl | ||||||
for k, v in pairs(request_table[name]) do | ||||||
tbl, err = _M.map_message(field_type, | ||||||
default_values and default_values[name], | ||||||
request_table[name], k) | ||||||
if not sub then | ||||||
sub = {} | ||||||
end | ||||||
sub[k]= tbl[k] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
end | ||||||
else | ||||||
sub, err = _M.map_message(field_type, | ||||||
default_values and default_values[name], | ||||||
request_table[name]) | ||||||
end | ||||||
|
||||||
if err then | ||||||
return nil, err | ||||||
end | ||||||
end | ||||||
|
||||||
request[name] = sub | ||||||
else | ||||||
if real_key then | ||||||
name = real_key | ||||||
end | ||||||
request[name] = get_from_request(request_table, name, field_type) | ||||||
or (default_values and default_values[name]) | ||||||
end | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ module github.com/api7/grpc_server_example | |
go 1.11 | ||
|
||
require ( | ||
github.com/golang/protobuf v1.5.0 // indirect | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please run |
||
golang.org/x/net v0.2.0 | ||
google.golang.org/grpc v1.32.0 | ||
google.golang.org/protobuf v1.27.1 | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Licensed to the Apache Software Foundation (ASF) under one or more | ||
// contributor license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright ownership. | ||
// The ASF licenses this file to You under the Apache License, Version 2.0 | ||
// (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
syntax = "proto3"; | ||
|
||
package echo; | ||
option go_package = "./proto"; | ||
|
||
import "google/protobuf/struct.proto"; | ||
|
||
service Echo { | ||
rpc EchoStruct (StructRequest) returns (StructReply) {} | ||
} | ||
|
||
message StructRequest { | ||
google.protobuf.Struct data = 1; | ||
} | ||
|
||
message StructReply { | ||
google.protobuf.Struct data = 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's check err before accessing tbl