Skip to content

Commit

Permalink
feat: update marshal (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
wgliyuli authored Nov 6, 2020
1 parent 40e4e20 commit 7176808
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions sonyflake/id.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sonyflake

import (
"fmt"
"strconv"
"time"
)
Expand All @@ -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
}
Expand Down

0 comments on commit 7176808

Please sign in to comment.