Browse Source

新增解析structpb的value和struct的方法

dcsunny 4 years ago
parent
commit
15a34d0145
1 changed files with 14 additions and 0 deletions
  1. 14 0
      common/json.go

+ 14 - 0
common/json.go

@@ -22,3 +22,17 @@ func NewStructValuePBByBytes(v []byte) *structpb.Value {
 	s.UnmarshalJSON(v)
 	return s
 }
+
+//UnMarshalPBValue obj为指针对象
+func UnMarshalPBValue(v *structpb.Value, obj interface{}) error {
+	j, err := v.MarshalJSON()
+	err = json.Unmarshal(j, obj)
+	return err
+}
+
+//UnMarshalPBStruct obj为指针对象
+func UnMarshalPBStruct(v *structpb.Struct, obj interface{}) error {
+	j, err := v.MarshalJSON()
+	err = json.Unmarshal(j, obj)
+	return err
+}