Skip to content

Commit

Permalink
testing new XID method
Browse files Browse the repository at this point in the history
  • Loading branch information
DalvinCodes committed Jun 9, 2023
1 parent d672a80 commit 83b90bb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions utils/xid.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ import (
type XID string

func NewXID() XID {
return XID(xid.New().Bytes())
return XID(xid.New().String())
}
func (id *XID) String() string {
return string(*id)
}

func (id XID) MarshalBSON() ([]byte, error) {
return json.Marshal(&id)
return json.Marshal(id)
}

func (id *XID) UnmarshalBSON(data []byte) error {
var tmp struct{ ID string }
var xid string

if err := json.Unmarshal(data, &tmp); err != nil {
if err := json.Unmarshal(data, &xid); err != nil {
return err
}

*id = XID(tmp.ID)
*id = XID(xid)

return nil
}

0 comments on commit 83b90bb

Please sign in to comment.