Skip to content

Commit

Permalink
General cleanup/improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
khaf committed Apr 13, 2015
1 parent 8b3acec commit 7cebfcc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
13 changes: 13 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,16 @@ func (ctn *Connection) Close() {
ctn.conn = nil
}
}

// Authenticate will send authentication information to the server.
func (ctn *Connection) Authenticate(user string, password []byte) error {
// need to authenticate
if user != "" {
command := newAdminCommand()
if err := command.authenticate(ctn, user, password); err != nil {
// Socket not authenticated. Do not put back into pool.
return err
}
}
return nil
}
13 changes: 6 additions & 7 deletions node_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@ func (ndv *nodeValidator) setAddress(timeout time.Duration) error {
defer conn.Close()

// need to authenticate
if ndv.cluster.user != "" {
command := newAdminCommand()
if err := command.authenticate(conn, ndv.cluster.user, ndv.cluster.password); err != nil {
// Socket not authenticated. Do not put back into pool.
conn.Close()
return err
}
// need to authenticate
if conn.Authenticate(ndv.cluster.user, ndv.cluster.password); err != nil {
// Socket not authenticated. Do not put back into pool.
conn.Close()

return err
}

if err := conn.SetTimeout(timeout); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions value.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (vl BytesValue) GetType() int {

// GetObject returns original value as an interface{}.
func (vl BytesValue) GetObject() interface{} {
return vl
return []byte(vl)
}

// func (vl BytesValue) GetLuaValue() LuaValue {
Expand Down Expand Up @@ -271,7 +271,7 @@ func (vl StringValue) GetType() int {

// GetObject returns original value as an interface{}.
func (vl StringValue) GetObject() interface{} {
return vl
return string(vl)
}

// func (vl StringValue) GetLuaValue() LuaValue {
Expand Down Expand Up @@ -369,7 +369,7 @@ func (vl LongValue) GetType() int {

// GetObject returns original value as an interface{}.
func (vl LongValue) GetObject() interface{} {
return vl
return int64(vl)
}

// func (vl LongValue) GetLuaValue() LuaValue {
Expand Down
2 changes: 1 addition & 1 deletion value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var _ = Describe("Value Test", func() {

bval := NewValue(person)
Expect(bval.GetType()).To(Equal(ParticleType.BLOB))
Expect(bval).To(BeAssignableToTypeOf(&BytesValue{}))
Expect(bval).To(BeAssignableToTypeOf(BytesValue{}))
Expect(bval.GetObject()).To(Equal([]byte(person.name)))
})
})
Expand Down

0 comments on commit 7cebfcc

Please sign in to comment.