Hello all,

I am using mongo-go-driver to replace globalsign-mgo, I want to write a new 
module for mongo-go instead of changing directly the existing module 
running on globalsign-mgo.

I facing a problem, there is a common data structure defined as below:

type Meeting struct {
// Id of the Meeting
ID bson.ObjectId `json:"id,omitempty" bson:"_id,omitempty"`
// UserId is the owner of the Meeting
UserID bson.ObjectId `json:"user_id,omitempty" bson:"user_id,omitempty"`
}

where the bson.ObjectId is defined in globalsign.mgo, but in the 
mongo-driver, it should be *primitive.bson.ObjectID, defined 
in "go.mongodb.org/mongo-driver/bson/primitive".

So when I make the object of Meeting from protobuf, if I using 
mongo-driver, the code looks like:

// FromProto buils a Meeting model from corresponding prototype
func FromProto(proto *proto.Meeting) *Meeting {
model := Meeting{}

if proto.Id != "" {
model.ID, _ = primitive.ObjectIDFromHex(proto.Id)
} else {
model.ID = primitive.NewObjectID()
}
model.UserID, _ = primitive.ObjectIDFromHex(proto.UserId)
       return &model
}

It looks the Meeting and the related operation code have to be deep coupled 
with either globalsign or mongo-driver. 
If I add a new Meeting struct for mongo-driver, a lot of code need to add 
or modify. Is there any way to dynamic switch the bson between globalsign 
and mongo-driver, so that the Meeting structure be compliant with two 
modules?

Thanks,

James

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9575e90a-1249-4229-baee-083e7986ef55%40googlegroups.com.

Reply via email to