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

fix golint, go vet and go fmt #44

Merged
merged 1 commit into from
Oct 6, 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
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
32 changes: 17 additions & 15 deletions bson/bson.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const (
BinaryUserDefined byte = 0x80
)

// A value implementing the bson.Getter interface will have its GetBSON
// 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 @@ -99,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 @@ -130,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")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially breaks backwards compat for little gain I'd say. @domodwyer, not sure how likely is this to be used?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is much of an issue, it's unlikely to be used by 99% of people.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, I am one of the 1% that's affected by this change. Add reactions here for "me too".


// 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 @@ -189,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 @@ -199,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 @@ -225,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 @@ -333,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 @@ -604,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 @@ -633,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