'Protobuf golang - How to read values from *_struct.Struct [closed]
I am trying to convert Protobuf *_struct.Struct to map[string]interface{} what is the right way to do it?
func convertToMap(input *_struct.Struct) map[string]interface{} {
ans := make(map[string]interface{})
//code to fill the map based on input
return ans
}
This is the Struct from protobuf repo: https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/struct.proto#L53
// The JSON representation for `Struct` is JSON object.
message Struct {
// Unordered map of dynamically typed values.
map<string, Value> fields = 1;
}
// `Value` represents a dynamically typed value which can be either
// null, a number, a string, a boolean, a recursive struct value, or a
// list of values. A producer of value is expected to set one of these
// variants. Absence of any variant indicates an error.
//
// The JSON representation for `Value` is JSON value.
message Value {
// The kind of value.
oneof kind {
// Represents a null value.
NullValue null_value = 1;
// Represents a double value.
double number_value = 2;
// Represents a string value.
string string_value = 3;
// Represents a boolean value.
bool bool_value = 4;
// Represents a structured value.
Struct struct_value = 5;
// Represents a repeated `Value`.
ListValue list_value = 6;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
