From 56b2b22f669b872fbc4e7c12dd400c0e2f3b2a0d Mon Sep 17 00:00:00 2001 From: Stanly Date: Thu, 27 Aug 2020 06:20:57 +0800 Subject: [PATCH] Add data json --- types/data.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/types/data.go b/types/data.go index b311fec..babdddc 100644 --- a/types/data.go +++ b/types/data.go @@ -1,6 +1,7 @@ package types import ( + "encoding/json" "errors" ) @@ -270,3 +271,17 @@ func (data Data) MustGetTimestamp(key string) Timestamp { value, _ := data.GetTimestamp(key) return value } + +func (data Data) JSON() ([]byte, error) { + bs, err := json.Marshal(&data) + if err != nil { + return nil, err + } + + return bs, nil +} + +func (data Data) MustJSON() []byte { + bs, _ := data.JSON() + return bs +}