Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Development #48

Merged
merged 20 commits into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ install:
- go get gopkg.in/check.v1
- go get gopkg.in/yaml.v2
- go get gopkg.in/tomb.v2
- go get github.com/golang/lint/golint

before_script:
- golint ./... | grep -v 'ID' | cat
- go vet github.com/globalsign/mgo/bson github.com/globalsign/mgo/txn github.com/globalsign/mgo
- export NOIPV6=1
- make startdb

Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@ Further PR's (with tests) are welcome, but please maintain backwards compatibili
* Hides SASL warnings ([details](https://github.com/globalsign/mgo/pull/7))
* Support for partial indexes ([detials](https://github.com/domodwyer/mgo/commit/5efe8eccb028238d93c222828cae4806aeae9f51))
* Fixes timezone handling ([details](https://github.com/go-mgo/mgo/pull/464))
* Integration tests run against newest MongoDB 3.2 releases ([details](https://github.com/globalsign/mgo/pull/4), [more](https://github.com/globalsign/mgo/pull/24))
* Integration tests run against MongoDB 3.2 & 3.4 releases ([details](https://github.com/globalsign/mgo/pull/4), [more](https://github.com/globalsign/mgo/pull/24), [more](https://github.com/globalsign/mgo/pull/35))
* Improved multi-document transaction performance ([details](https://github.com/globalsign/mgo/pull/10), [more](https://github.com/globalsign/mgo/pull/11), [more](https://github.com/globalsign/mgo/pull/16))
* Fixes cursor timeouts ([details](https://jira.mongodb.org/browse/SERVER-24899))
* Support index hints and timeouts for count queries ([details](https://github.com/globalsign/mgo/pull/17))
* Don't panic when handling indexed `int64` fields ([detials](https://github.com/go-mgo/mgo/issues/475))
* Supports dropping all indexes on a collection ([details](https://github.com/globalsign/mgo/pull/25))
* Annotates log entries/profiler output with optional appName on 3.4+ ([details](https://github.com/globalsign/mgo/pull/28))
* Support for read-only [views](https://docs.mongodb.com/manual/core/views/) in 3.4+ ([details](https://github.com/globalsign/mgo/pull/33))
* Support for [collations](https://docs.mongodb.com/manual/reference/collation/) in 3.4+ ([details](https://github.com/globalsign/mgo/pull/37))
* Provide BSON constants for convenience/sanity ([details](https://github.com/globalsign/mgo/pull/41))
* Consistently unmarshal time.Time values as UTC ([details](https://github.com/globalsign/mgo/pull/42))
* Enforces best practise coding guidelines ([details](https://github.com/globalsign/mgo/pull/44))
* GetBSON correctly handles structs with both fields and pointers ([details](https://github.com/globalsign/mgo/pull/40))

---

### Thanks to
* @bozaro
* @BenLubar
* @carter2000
* @cezarsa
Expand All @@ -37,6 +43,7 @@ Further PR's (with tests) are welcome, but please maintain backwards compatibili
* @feliixx
* @fmpwizard
* @jameinel
* @gazoon
* @mapete94
* @Reenjii
* @smoya
Expand Down
2 changes: 1 addition & 1 deletion auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type getNonceCmd struct {

type getNonceResult struct {
Nonce string
Err string "$err"
Err string `bson:"$err"`
Code int
}

Expand Down
10 changes: 5 additions & 5 deletions auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func (s *S) TestAuthLoginCachingWithNewSession(c *C) {
}

func (s *S) TestAuthLoginCachingAcrossPool(c *C) {
// Logins are cached even when the conenction goes back
// Logins are cached even when the connection goes back
// into the pool.

session, err := mgo.Dial("localhost:40002")
Expand Down Expand Up @@ -934,7 +934,7 @@ func (s *S) TestAuthX509Cred(c *C) {
x509Subject := "CN=localhost,OU=Client,O=MGO,L=MGO,ST=MGO,C=GO"

externalDB := session.DB("$external")
var x509User mgo.User = mgo.User{
var x509User = mgo.User{
Username: x509Subject,
OtherDBRoles: map[string][]mgo.Role{"admin": {mgo.RoleRoot}},
}
Expand Down Expand Up @@ -1080,11 +1080,11 @@ func (kerberosSuite *KerberosSuite) TestAuthKerberosURL(c *C) {
c.Skip("no -kerberos")
}
c.Logf("Connecting to %s...", kerberosHost)
connectUri := url.QueryEscape(kerberosUser) + "@" + kerberosHost + "?authMechanism=GSSAPI"
connectURI := url.QueryEscape(kerberosUser) + "@" + kerberosHost + "?authMechanism=GSSAPI"
if runtime.GOOS == "windows" {
connectUri = url.QueryEscape(kerberosUser) + ":" + url.QueryEscape(getWindowsKerberosPassword()) + "@" + kerberosHost + "?authMechanism=GSSAPI"
connectURI = url.QueryEscape(kerberosUser) + ":" + url.QueryEscape(getWindowsKerberosPassword()) + "@" + kerberosHost + "?authMechanism=GSSAPI"
}
session, err := mgo.Dial(connectUri)
session, err := mgo.Dial(connectURI)
c.Assert(err, IsNil)
defer session.Close()
n, err := session.DB("kerberos").C("test").Find(M{}).Count()
Expand Down
65 changes: 50 additions & 15 deletions bson/bson.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,40 @@ import (
// --------------------------------------------------------------------------
// The public API.

// A value implementing the bson.Getter interface will have its GetBSON
// Element types constants from BSON specification.
const (
ElementFloat64 byte = 0x01
ElementString byte = 0x02
ElementDocument byte = 0x03
ElementArray byte = 0x04
ElementBinary byte = 0x05
Element06 byte = 0x06
ElementObjectId byte = 0x07
ElementBool byte = 0x08
ElementDatetime byte = 0x09
ElementNil byte = 0x0A
ElementRegEx byte = 0x0B
ElementDBPointer byte = 0x0C
ElementJavaScriptWithoutScope byte = 0x0D
ElementSymbol byte = 0x0E
ElementJavaScriptWithScope byte = 0x0F
ElementInt32 byte = 0x10
ElementTimestamp byte = 0x11
ElementInt64 byte = 0x12
ElementDecimal128 byte = 0x13
ElementMinKey byte = 0xFF
ElementMaxKey byte = 0x7F

BinaryGeneric byte = 0x00
BinaryFunction byte = 0x01
BinaryBinaryOld byte = 0x02
BinaryUUIDOld byte = 0x03
BinaryUUID byte = 0x04
BinaryMD5 byte = 0x05
BinaryUserDefined byte = 0x80
)

// Getter interface: a value implementing the bson.Getter interface will have its GetBSON
// method called when the given value has to be marshalled, and the result
// of this method will be marshaled in place of the actual object.
//
Expand All @@ -66,12 +99,12 @@ type Getter interface {
GetBSON() (interface{}, error)
}

// A value implementing the bson.Setter interface will receive the BSON
// Setter interface: a value implementing the bson.Setter interface will receive the BSON
// value via the SetBSON method during unmarshaling, and the object
// itself will not be changed as usual.
//
// If setting the value works, the method should return nil or alternatively
// bson.SetZero to set the respective field to its zero value (nil for
// bson.ErrSetZero to set the respective field to its zero value (nil for
// pointer types). If SetBSON returns a value of type bson.TypeError, the
// BSON value will be omitted from a map or slice being decoded and the
// unmarshalling will continue. If it returns any other non-nil error, the
Expand All @@ -97,10 +130,10 @@ type Setter interface {
SetBSON(raw Raw) error
}

// SetZero may be returned from a SetBSON method to have the value set to
// ErrSetZero may be returned from a SetBSON method to have the value set to
// its respective zero value. When used in pointer values, this will set the
// field to nil rather than to the pre-allocated value.
var SetZero = errors.New("set to zero")
var ErrSetZero = errors.New("set to zero")

// M is a convenient alias for a map[string]interface{} map, useful for
// dealing with BSON in a native way. For instance:
Expand Down Expand Up @@ -156,7 +189,7 @@ type Raw struct {
// documents in general.
type RawD []RawDocElem

// See the RawD type.
// RawDocElem elements of RawD type.
type RawDocElem struct {
Name string
Value Raw
Expand All @@ -166,7 +199,7 @@ type RawDocElem struct {
// long. MongoDB objects by default have such a property set in their "_id"
// property.
//
// http://www.mongodb.org/display/DOCS/Object+IDs
// http://www.mongodb.org/display/DOCS/Object+Ids
type ObjectId string

// ObjectIdHex returns an ObjectId from the provided hex representation.
Expand All @@ -192,7 +225,7 @@ func IsObjectIdHex(s string) bool {

// objectIdCounter is atomically incremented when generating a new ObjectId
// using NewObjectId() function. It's used as a counter part of an id.
var objectIdCounter uint32 = readRandomUint32()
var objectIdCounter = readRandomUint32()

// readRandomUint32 returns a random objectIdCounter.
func readRandomUint32() uint32 {
Expand Down Expand Up @@ -300,12 +333,12 @@ func (id *ObjectId) UnmarshalJSON(data []byte) error {
return nil
}
if len(data) != 26 || data[0] != '"' || data[25] != '"' {
return errors.New(fmt.Sprintf("invalid ObjectId in JSON: %s", string(data)))
return fmt.Errorf("invalid ObjectId in JSON: %s", string(data))
}
var buf [12]byte
_, err := hex.Decode(buf[:], data[1:25])
if err != nil {
return errors.New(fmt.Sprintf("invalid ObjectId in JSON: %s (%s)", string(data), err))
return fmt.Errorf("invalid ObjectId in JSON: %s (%s)", string(data), err)
}
*id = ObjectId(string(buf[:]))
return nil
Expand Down Expand Up @@ -571,12 +604,12 @@ func Unmarshal(in []byte, out interface{}) (err error) {
d := newDecoder(in)
d.readDocTo(v)
if d.i < len(d.in) {
return errors.New("Document is corrupted")
return errors.New("document is corrupted")
}
case reflect.Struct:
return errors.New("Unmarshal can't deal with struct values. Use a pointer.")
return errors.New("unmarshal can't deal with struct values. Use a pointer")
default:
return errors.New("Unmarshal needs a map or a pointer to a struct.")
return errors.New("unmarshal needs a map or a pointer to a struct")
}
return nil
}
Expand All @@ -600,13 +633,15 @@ func (raw Raw) Unmarshal(out interface{}) (err error) {
return &TypeError{v.Type(), raw.Kind}
}
case reflect.Struct:
return errors.New("Raw Unmarshal can't deal with struct values. Use a pointer.")
return errors.New("raw Unmarshal can't deal with struct values. Use a pointer")
default:
return errors.New("Raw Unmarshal needs a map or a valid pointer.")
return errors.New("raw Unmarshal needs a map or a valid pointer")
}
return nil
}

// TypeError store details for type error occuring
// during unmarshaling
type TypeError struct {
Type reflect.Type
Kind byte
Expand Down
Loading