Explorar o código

新增NewStructValuePB

dcsunny %!s(int64=4) %!d(string=hai) anos
pai
achega
d925262549
Modificáronse 1 ficheiros con 11 adicións e 1 borrados
  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
+}