Skip to content

Bridges the gap between the primitive package of the mongo-go-driver and increases resiliency and functionality

Notifications You must be signed in to change notification settings

qhenkart/objectid-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ObjectID-Go

GoDoc CircleCI

ObjectID-Go helps to bridge the gap between the new mongo-go-driver and previous community run drivers such as mgo.

For people not migrating, this also helps cover some of the pitfalls and frustrations of mongo-go-driver's primitive package which is extremely brittle, leaks too much of the driver to the clients of the API, and can even cause unexpected panics when unmarshalling

This package follows the community run driver standard of using strings to represent objectIDs instead of [12]bytes, allowing for a much smoother development experience.

Features

  1. This package automatically converts all oid.ObjectID types into primitive.ObjectIDs when marshalling or unmarshalling into bson
  2. no panics on JSON unmarshalling
  3. uses string types to avoid the driver bleeding to the API and give more control to the dev
  4. fixes vet errors that was rampant in the community drivers
  5. combines the best features of community drivers and the primitive package
  6. makes migrating significantly easier

Install

go get -u github.com/qhenkart/objectid-go

or

dep ensure --add github.com/qhenkart/objectid-go

Usage

type User struct {
  ID oid.ObjectID `bson:"_id" json:"id"`
}

and use the struct with json un/marshallers and the mongo-go-driver methods without a second thought

Check the godocs for additional functionality and helpers

About

Bridges the gap between the primitive package of the mongo-go-driver and increases resiliency and functionality

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages