2020-09-18 19:36:12 +00:00
|
|
|
package pbservice
|
|
|
|
|
|
|
|
import (
|
2023-01-11 14:39:10 +00:00
|
|
|
"google.golang.org/protobuf/types/known/structpb"
|
2020-09-18 19:36:12 +00:00
|
|
|
)
|
|
|
|
|
2023-01-11 14:39:10 +00:00
|
|
|
// ProtobufTypesStructToMapStringInterface converts a protobuf/structpb.Struct into a
|
2020-09-18 19:36:12 +00:00
|
|
|
// map[string]interface{}.
|
2023-01-11 14:39:10 +00:00
|
|
|
func ProtobufTypesStructToMapStringInterface(s *structpb.Struct) map[string]interface{} {
|
2020-09-18 19:36:12 +00:00
|
|
|
if s == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2023-01-11 14:39:10 +00:00
|
|
|
return s.AsMap()
|
2020-09-18 19:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MapStringInterfaceToProtobufTypesStruct converts a map[string]interface{} into a proto.Struct
|
2023-01-11 14:39:10 +00:00
|
|
|
func MapStringInterfaceToProtobufTypesStruct(m map[string]interface{}) *structpb.Struct {
|
|
|
|
if len(m) < 1 {
|
2020-09-18 19:36:12 +00:00
|
|
|
return nil
|
|
|
|
}
|
2023-01-11 14:39:10 +00:00
|
|
|
// TODO - handle the error better. It probably requires mog to be able to use alternative method signatures though
|
|
|
|
s, _ := structpb.NewStruct(m)
|
|
|
|
return s
|
2020-09-18 19:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SliceToPBListValue converts a []interface{} into a proto.ListValue. It's used
|
|
|
|
// internally by MapStringInterfaceToProtobufTypesStruct when it encouters slices.
|
2023-01-11 14:39:10 +00:00
|
|
|
// TODO (remove usage of this struct in favor of structpb.NewListValue)
|
|
|
|
func SliceToPBListValue(s []interface{}) *structpb.ListValue {
|
|
|
|
if len(s) < 1 {
|
2020-09-18 19:36:12 +00:00
|
|
|
return nil
|
|
|
|
}
|
2023-01-11 14:39:10 +00:00
|
|
|
// TODO - handle the error better. It probably requires mog to use alt method signatures though
|
|
|
|
val, _ := structpb.NewList(s)
|
|
|
|
return val
|
2020-09-18 19:36:12 +00:00
|
|
|
}
|