Skip to content

Commit d672a80

Browse files
committed
testing new XID method
1 parent 904d7b2 commit d672a80

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

utils/xid.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package utils
22

33
import (
4+
"encoding/json"
5+
46
"github.com/rs/xid"
5-
"go.mongodb.org/mongo-driver/bson"
67
)
78

89
type XID string
@@ -15,15 +16,13 @@ func (id *XID) String() string {
1516
}
1617

1718
func (id XID) MarshalBSON() ([]byte, error) {
18-
return bson.Marshal(struct {
19-
ID string
20-
}{string(id)})
19+
return json.Marshal(&id)
2120
}
2221

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

26-
if err := bson.Unmarshal(data, &tmp); err != nil {
25+
if err := json.Unmarshal(data, &tmp); err != nil {
2726
return err
2827
}
2928

0 commit comments

Comments
 (0)