Skip to content

Commit 3140581

Browse files
authored
Added support for map[string]map[string]string protobuf conversion (#510)
1 parent 1ca402f commit 3140581

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

operator/builtin/output/googlecloud/proto.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ func toProto(v interface{}) (*structpb.Value, error) {
5555
for key, value := range v {
5656
fields[key] = structpb.NewStringValue(value)
5757
}
58+
return structpb.NewStructValue(&structpb.Struct{
59+
Fields: fields,
60+
}), nil
61+
case map[string]map[string]string:
62+
fields := map[string]*structpb.Value{}
63+
for key, value := range v {
64+
proto, err := toProto(value)
65+
if err != nil {
66+
return nil, err
67+
}
68+
69+
fields[key] = proto
70+
}
71+
5872
return structpb.NewStructValue(&structpb.Struct{
5973
Fields: fields,
6074
}), nil

operator/builtin/output/googlecloud/proto_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ func TestToProto(t *testing.T) {
6363
},
6464
}),
6565
},
66+
{
67+
name: "map[string]map[string]string",
68+
value: map[string]map[string]string{
69+
"test": {
70+
"key": "value",
71+
},
72+
},
73+
expectedValue: structpb.NewStructValue(&structpb.Struct{
74+
Fields: map[string]*structpb.Value{
75+
"test": structpb.NewStructValue(&structpb.Struct{
76+
Fields: map[string]*structpb.Value{
77+
"key": structpb.NewStringValue("value"),
78+
},
79+
}),
80+
},
81+
}),
82+
},
6683
{
6784
name: "interface list",
6885
value: []interface{}{"value", 1},

0 commit comments

Comments
 (0)