Quellcode durchsuchen

新增NewStructValuePB

dcsunny vor 4 Jahren
Ursprung
Commit
d925262549
1 geänderte Dateien mit 11 neuen und 1 gelöschten Zeilen
  1. 11 1
      common/json.go

+ 11 - 1
common/json.go

@@ -1,8 +1,18 @@
 package common
 
-import "encoding/json"
+import (
+	"encoding/json"
+
+	"google.golang.org/protobuf/types/known/structpb"
+)
 
 func MarshalJSON(v interface{}) []byte {
 	j, _ := json.Marshal(v)
 	return j
 }
+
+func NewStructValuePB(v interface{}) *structpb.Value {
+	s := new(structpb.Value)
+	s.UnmarshalJSON(MarshalJSON(v))
+	return s
+}