Skip to content

Commit 3f3792e

Browse files
committed
Merge branch 'development' into merge
* development: readme: credit @bozaro (#47) Fix GetBSON() method usage (#40) readme: credit @feliixx (#46) fix golint, go vet and gofmt warnings (#44) readme: add missing features / credit bson.Unmarshal returns time in UTC (#42) Introduce constants for BSON element types (#41) Test against MongoDB 3.4.x (#35) Add collation option to collection.Create() (#37) Don't panic on indexed int64 fields (#23) readme: credit @feliixx in the README (#36) add method CreateView() (#33) Update README to add appName (#32) send metadata during handshake (#28) readme: credit @feliixx for #25 (#26) add DropAllIndexes() method (#25) # Conflicts: # README.md # cluster.go # session.go # session_test.go
2 parents 3dbb487 + 12fb1c2 commit 3f3792e

33 files changed

+951
-629
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ install:
3333
- go get gopkg.in/check.v1
3434
- go get gopkg.in/yaml.v2
3535
- go get gopkg.in/tomb.v2
36+
- go get github.com/golang/lint/golint
3637

3738
before_script:
39+
- golint ./... | grep -v 'ID' | cat
40+
- go vet github.com/globalsign/mgo/bson github.com/globalsign/mgo/txn github.com/globalsign/mgo
3841
- export NOIPV6=1
3942
- make startdb
4043

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,24 @@ Further PR's (with tests) are welcome, but please maintain backwards compatibili
1717
* Hides SASL warnings ([details](https://github.com/globalsign/mgo/pull/7))
1818
* Support for partial indexes ([detials](https://github.com/domodwyer/mgo/commit/5efe8eccb028238d93c222828cae4806aeae9f51))
1919
* Fixes timezone handling ([details](https://github.com/go-mgo/mgo/pull/464))
20-
* 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))
20+
* 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))
2121
* 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))
2222
* Fixes cursor timeouts ([details](https://jira.mongodb.org/browse/SERVER-24899))
2323
* Support index hints and timeouts for count queries ([details](https://github.com/globalsign/mgo/pull/17))
2424
* Don't panic when handling indexed `int64` fields ([detials](https://github.com/go-mgo/mgo/issues/475))
2525
* Supports dropping all indexes on a collection ([details](https://github.com/globalsign/mgo/pull/25))
2626
* Annotates log entries/profiler output with optional appName on 3.4+ ([details](https://github.com/globalsign/mgo/pull/28))
2727
* Support for read-only [views](https://docs.mongodb.com/manual/core/views/) in 3.4+ ([details](https://github.com/globalsign/mgo/pull/33))
28+
* Support for [collations](https://docs.mongodb.com/manual/reference/collation/) in 3.4+ ([details](https://github.com/globalsign/mgo/pull/37))
29+
* Provide BSON constants for convenience/sanity ([details](https://github.com/globalsign/mgo/pull/41))
30+
* Consistently unmarshal time.Time values as UTC ([details](https://github.com/globalsign/mgo/pull/42))
31+
* Enforces best practise coding guidelines ([details](https://github.com/globalsign/mgo/pull/44))
32+
* GetBSON correctly handles structs with both fields and pointers ([details](https://github.com/globalsign/mgo/pull/40))
2833

2934
---
3035

3136
### Thanks to
37+
* @bozaro
3238
* @BenLubar
3339
* @carter2000
3440
* @cezarsa
@@ -37,6 +43,7 @@ Further PR's (with tests) are welcome, but please maintain backwards compatibili
3743
* @feliixx
3844
* @fmpwizard
3945
* @jameinel
46+
* @gazoon
4047
* @mapete94
4148
* @Reenjii
4249
* @smoya

auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type getNonceCmd struct {
6161

6262
type getNonceResult struct {
6363
Nonce string
64-
Err string "$err"
64+
Err string `bson:"$err"`
6565
Code int
6666
}
6767

auth_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ func (s *S) TestAuthLoginCachingWithNewSession(c *C) {
580580
}
581581

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

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

936936
externalDB := session.DB("$external")
937-
var x509User mgo.User = mgo.User{
937+
var x509User = mgo.User{
938938
Username: x509Subject,
939939
OtherDBRoles: map[string][]mgo.Role{"admin": {mgo.RoleRoot}},
940940
}
@@ -1080,11 +1080,11 @@ func (kerberosSuite *KerberosSuite) TestAuthKerberosURL(c *C) {
10801080
c.Skip("no -kerberos")
10811081
}
10821082
c.Logf("Connecting to %s...", kerberosHost)
1083-
connectUri := url.QueryEscape(kerberosUser) + "@" + kerberosHost + "?authMechanism=GSSAPI"
1083+
connectURI := url.QueryEscape(kerberosUser) + "@" + kerberosHost + "?authMechanism=GSSAPI"
10841084
if runtime.GOOS == "windows" {
1085-
connectUri = url.QueryEscape(kerberosUser) + ":" + url.QueryEscape(getWindowsKerberosPassword()) + "@" + kerberosHost + "?authMechanism=GSSAPI"
1085+
connectURI = url.QueryEscape(kerberosUser) + ":" + url.QueryEscape(getWindowsKerberosPassword()) + "@" + kerberosHost + "?authMechanism=GSSAPI"
10861086
}
1087-
session, err := mgo.Dial(connectUri)
1087+
session, err := mgo.Dial(connectURI)
10881088
c.Assert(err, IsNil)
10891089
defer session.Close()
10901090
n, err := session.DB("kerberos").C("test").Find(M{}).Count()

bson/bson.go

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,40 @@ import (
5656
// --------------------------------------------------------------------------
5757
// The public API.
5858

59-
// A value implementing the bson.Getter interface will have its GetBSON
59+
// Element types constants from BSON specification.
60+
const (
61+
ElementFloat64 byte = 0x01
62+
ElementString byte = 0x02
63+
ElementDocument byte = 0x03
64+
ElementArray byte = 0x04
65+
ElementBinary byte = 0x05
66+
Element06 byte = 0x06
67+
ElementObjectId byte = 0x07
68+
ElementBool byte = 0x08
69+
ElementDatetime byte = 0x09
70+
ElementNil byte = 0x0A
71+
ElementRegEx byte = 0x0B
72+
ElementDBPointer byte = 0x0C
73+
ElementJavaScriptWithoutScope byte = 0x0D
74+
ElementSymbol byte = 0x0E
75+
ElementJavaScriptWithScope byte = 0x0F
76+
ElementInt32 byte = 0x10
77+
ElementTimestamp byte = 0x11
78+
ElementInt64 byte = 0x12
79+
ElementDecimal128 byte = 0x13
80+
ElementMinKey byte = 0xFF
81+
ElementMaxKey byte = 0x7F
82+
83+
BinaryGeneric byte = 0x00
84+
BinaryFunction byte = 0x01
85+
BinaryBinaryOld byte = 0x02
86+
BinaryUUIDOld byte = 0x03
87+
BinaryUUID byte = 0x04
88+
BinaryMD5 byte = 0x05
89+
BinaryUserDefined byte = 0x80
90+
)
91+
92+
// Getter interface: a value implementing the bson.Getter interface will have its GetBSON
6093
// method called when the given value has to be marshalled, and the result
6194
// of this method will be marshaled in place of the actual object.
6295
//
@@ -66,12 +99,12 @@ type Getter interface {
6699
GetBSON() (interface{}, error)
67100
}
68101

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

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

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

159-
// See the RawD type.
192+
// RawDocElem elements of RawD type.
160193
type RawDocElem struct {
161194
Name string
162195
Value Raw
@@ -166,7 +199,7 @@ type RawDocElem struct {
166199
// long. MongoDB objects by default have such a property set in their "_id"
167200
// property.
168201
//
169-
// http://www.mongodb.org/display/DOCS/Object+IDs
202+
// http://www.mongodb.org/display/DOCS/Object+Ids
170203
type ObjectId string
171204

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

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

197230
// readRandomUint32 returns a random objectIdCounter.
198231
func readRandomUint32() uint32 {
@@ -300,12 +333,12 @@ func (id *ObjectId) UnmarshalJSON(data []byte) error {
300333
return nil
301334
}
302335
if len(data) != 26 || data[0] != '"' || data[25] != '"' {
303-
return errors.New(fmt.Sprintf("invalid ObjectId in JSON: %s", string(data)))
336+
return fmt.Errorf("invalid ObjectId in JSON: %s", string(data))
304337
}
305338
var buf [12]byte
306339
_, err := hex.Decode(buf[:], data[1:25])
307340
if err != nil {
308-
return errors.New(fmt.Sprintf("invalid ObjectId in JSON: %s (%s)", string(data), err))
341+
return fmt.Errorf("invalid ObjectId in JSON: %s (%s)", string(data), err)
309342
}
310343
*id = ObjectId(string(buf[:]))
311344
return nil
@@ -571,12 +604,12 @@ func Unmarshal(in []byte, out interface{}) (err error) {
571604
d := newDecoder(in)
572605
d.readDocTo(v)
573606
if d.i < len(d.in) {
574-
return errors.New("Document is corrupted")
607+
return errors.New("document is corrupted")
575608
}
576609
case reflect.Struct:
577-
return errors.New("Unmarshal can't deal with struct values. Use a pointer.")
610+
return errors.New("unmarshal can't deal with struct values. Use a pointer")
578611
default:
579-
return errors.New("Unmarshal needs a map or a pointer to a struct.")
612+
return errors.New("unmarshal needs a map or a pointer to a struct")
580613
}
581614
return nil
582615
}
@@ -600,13 +633,15 @@ func (raw Raw) Unmarshal(out interface{}) (err error) {
600633
return &TypeError{v.Type(), raw.Kind}
601634
}
602635
case reflect.Struct:
603-
return errors.New("Raw Unmarshal can't deal with struct values. Use a pointer.")
636+
return errors.New("raw Unmarshal can't deal with struct values. Use a pointer")
604637
default:
605-
return errors.New("Raw Unmarshal needs a map or a valid pointer.")
638+
return errors.New("raw Unmarshal needs a map or a valid pointer")
606639
}
607640
return nil
608641
}
609642

643+
// TypeError store details for type error occuring
644+
// during unmarshaling
610645
type TypeError struct {
611646
Type reflect.Type
612647
Kind byte

0 commit comments

Comments
 (0)