Skip to content

Commit

Permalink
fix unmarshal null character string to return 0 (#25)
Browse files Browse the repository at this point in the history
* feat: add sonyflake

* fix: unmarshal 0
  • Loading branch information
wgliyuli authored Apr 9, 2021
1 parent b557172 commit 4678acb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sonyflake/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func (i ID) MarshalText() ([]byte, error) {

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

0 comments on commit 4678acb

Please sign in to comment.