Skip to content

Commit

Permalink
feat: update marshal int to string (#18)
Browse files Browse the repository at this point in the history
* feat: update marshal int to string

* feat: update function param name
  • Loading branch information
wgliyuli committed Nov 6, 2020
1 parent 4742195 commit eb4f6c5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sonyflake/id.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sonyflake

import (
"fmt"
"strconv"
"time"
)
Expand All @@ -16,12 +17,11 @@ func IDFromString(s string) (ID, error) {
}

func (i *ID) MarshalJSON() ([]byte, error) {
b := []byte(strconv.FormatInt(int64(*i), 10))
return b, nil
return []byte(fmt.Sprintf("\"%v\"", i)), nil
}

func (i *ID) UnmarshalJSON(b []byte) error {
id, err := strconv.ParseInt(string(b), 10, 64)
id, err := strconv.ParseInt(string(b[1:len(b)-1]), 10, 32)
if err != nil {
return err
}
Expand Down

0 comments on commit eb4f6c5

Please sign in to comment.