Skip to content

Commit 97bd0cd

Browse files
feliixxdomodwyer
authored andcommitted
fix golint, go vet and gofmt warnings (#44)
Fixes #43
1 parent c86ed84 commit 97bd0cd

32 files changed

+764
-611
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

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: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const (
8989
BinaryUserDefined byte = 0x80
9090
)
9191

92-
// A value implementing the bson.Getter interface will have its GetBSON
92+
// Getter interface: a value implementing the bson.Getter interface will have its GetBSON
9393
// method called when the given value has to be marshalled, and the result
9494
// of this method will be marshaled in place of the actual object.
9595
//
@@ -99,12 +99,12 @@ type Getter interface {
9999
GetBSON() (interface{}, error)
100100
}
101101

102-
// 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
103103
// value via the SetBSON method during unmarshaling, and the object
104104
// itself will not be changed as usual.
105105
//
106106
// If setting the value works, the method should return nil or alternatively
107-
// 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
108108
// pointer types). If SetBSON returns a value of type bson.TypeError, the
109109
// BSON value will be omitted from a map or slice being decoded and the
110110
// unmarshalling will continue. If it returns any other non-nil error, the
@@ -130,10 +130,10 @@ type Setter interface {
130130
SetBSON(raw Raw) error
131131
}
132132

133-
// 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
134134
// its respective zero value. When used in pointer values, this will set the
135135
// field to nil rather than to the pre-allocated value.
136-
var SetZero = errors.New("set to zero")
136+
var ErrSetZero = errors.New("set to zero")
137137

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

192-
// See the RawD type.
192+
// RawDocElem elements of RawD type.
193193
type RawDocElem struct {
194194
Name string
195195
Value Raw
@@ -199,7 +199,7 @@ type RawDocElem struct {
199199
// long. MongoDB objects by default have such a property set in their "_id"
200200
// property.
201201
//
202-
// http://www.mongodb.org/display/DOCS/Object+IDs
202+
// http://www.mongodb.org/display/DOCS/Object+Ids
203203
type ObjectId string
204204

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

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

230230
// readRandomUint32 returns a random objectIdCounter.
231231
func readRandomUint32() uint32 {
@@ -333,12 +333,12 @@ func (id *ObjectId) UnmarshalJSON(data []byte) error {
333333
return nil
334334
}
335335
if len(data) != 26 || data[0] != '"' || data[25] != '"' {
336-
return errors.New(fmt.Sprintf("invalid ObjectId in JSON: %s", string(data)))
336+
return fmt.Errorf("invalid ObjectId in JSON: %s", string(data))
337337
}
338338
var buf [12]byte
339339
_, err := hex.Decode(buf[:], data[1:25])
340340
if err != nil {
341-
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)
342342
}
343343
*id = ObjectId(string(buf[:]))
344344
return nil
@@ -604,12 +604,12 @@ func Unmarshal(in []byte, out interface{}) (err error) {
604604
d := newDecoder(in)
605605
d.readDocTo(v)
606606
if d.i < len(d.in) {
607-
return errors.New("Document is corrupted")
607+
return errors.New("document is corrupted")
608608
}
609609
case reflect.Struct:
610-
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")
611611
default:
612-
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")
613613
}
614614
return nil
615615
}
@@ -633,13 +633,15 @@ func (raw Raw) Unmarshal(out interface{}) (err error) {
633633
return &TypeError{v.Type(), raw.Kind}
634634
}
635635
case reflect.Struct:
636-
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")
637637
default:
638-
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")
639639
}
640640
return nil
641641
}
642642

643+
// TypeError store details for type error occuring
644+
// during unmarshaling
643645
type TypeError struct {
644646
Type reflect.Type
645647
Kind byte

0 commit comments

Comments
 (0)