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 904d7b2 commit d672a80
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions utils/xid.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package utils

import (
"encoding/json"

"github.com/rs/xid"
"go.mongodb.org/mongo-driver/bson"
)

type XID string
Expand All @@ -15,15 +16,13 @@ func (id *XID) String() string {
}

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

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

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

Expand Down

0 comments on commit d672a80

Please sign in to comment.