From 7176808959622491e3cea1b102f06f6bb91e3286 Mon Sep 17 00:00:00 2001 From: Lincoln_Lee <138951227@qq.com> Date: Fri, 6 Nov 2020 15:59:39 +0800 Subject: [PATCH] feat: update marshal (#20) --- sonyflake/id.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/sonyflake/id.go b/sonyflake/id.go index 1ea2ba2..0cf81af 100644 --- a/sonyflake/id.go +++ b/sonyflake/id.go @@ -1,7 +1,6 @@ package sonyflake import ( - "fmt" "strconv" "time" ) @@ -16,12 +15,12 @@ func IDFromString(s string) (ID, error) { return ID(id), nil } -func (i *ID) MarshalJSON() ([]byte, error) { - return []byte(fmt.Sprintf("\"%v\"", i)), nil +func (i *ID) MarshalText() ([]byte, error) { + return []byte(strconv.FormatInt(int64(*i), 10)), nil } -func (i *ID) UnmarshalJSON(b []byte) error { - id, err := strconv.ParseInt(string(b[1:len(b)-1]), 10, 64) +func (i *ID) UnmarshalText(b []byte) error { + id, err := strconv.ParseInt(string(b), 10, 64) if err != nil { return err }