leaf/objectid.go

24 lines
438 B
Go
Raw Normal View History

2024-01-07 05:40:41 +00:00
package leaf
import (
"go.mongodb.org/mongo-driver/bson/primitive"
)
func ObjectIDFromHex(hex string) primitive.ObjectID {
id, err := primitive.ObjectIDFromHex(hex)
if err != nil {
return primitive.NilObjectID
}
return id
}
func ObjectIDFromHexSlice(hexSlice []string) []primitive.ObjectID {
ids := make([]primitive.ObjectID, len(hexSlice))
for i := range hexSlice {
ids[i] = ObjectIDFromHex(hexSlice[i])
}
return ids
}