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 83b90bb commit 6c79e16
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions utils/xid.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import (
"github.com/rs/xid"
)

type XID string
type XID struct {
ID string `json:"_id" bson:"_id"`
}

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

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

func (id *XID) UnmarshalBSON(data []byte) error {
Expand All @@ -26,7 +28,7 @@ func (id *XID) UnmarshalBSON(data []byte) error {
return err
}

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

return nil
}

0 comments on commit 6c79e16

Please sign in to comment.