json.go 418 B

123456789101112131415161718192021222324
  1. package common
  2. import (
  3. "encoding/json"
  4. "google.golang.org/protobuf/types/known/structpb"
  5. )
  6. func MarshalJSON(v interface{}) []byte {
  7. j, _ := json.Marshal(v)
  8. return j
  9. }
  10. func NewStructValuePB(v interface{}) *structpb.Value {
  11. s := new(structpb.Value)
  12. s.UnmarshalJSON(MarshalJSON(v))
  13. return s
  14. }
  15. func NewStructValuePBByBytes(v []byte) *structpb.Value {
  16. s := new(structpb.Value)
  17. s.UnmarshalJSON(v)
  18. return s
  19. }