From 9c7193f3ad5db4ed0b0cba82c8e4f3c7def83f5e Mon Sep 17 00:00:00 2001 From: Dusty Wilson Date: Sun, 22 Feb 2015 02:54:06 -0800 Subject: [PATCH 1/2] Added NewConnWithUser to allow users other than the default --- rados/rados.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/rados/rados.go b/rados/rados.go index eadad11..935bc24 100644 --- a/rados/rados.go +++ b/rados/rados.go @@ -7,6 +7,7 @@ import "C" import ( "fmt" + "unsafe" ) type RadosError int @@ -35,3 +36,19 @@ func NewConn() (*Conn, error) { return nil, RadosError(int(ret)) } } + +// NewConnWithUser creates a new connection object with a custom username. +// It returns the connection and an error, if any. +func NewConnWithUser(user string) (*Conn, error) { + c_user := C.CString(user) + defer C.free(unsafe.Pointer(c_user)) + + conn := &Conn{} + ret := C.rados_create(&conn.cluster, c_user) + + if ret == 0 { + return conn, nil + } else { + return nil, RadosError(int(ret)) + } +} From f8de1c7f5a3851bc9b0866b5f154f4c7d0c43ab9 Mon Sep 17 00:00:00 2001 From: Dusty Wilson Date: Sun, 22 Feb 2015 13:09:13 -0800 Subject: [PATCH 2/2] Added test for NewConnWithUser --- rados/rados_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rados/rados_test.go b/rados/rados_test.go index 4bbe99f..ebff9f3 100644 --- a/rados/rados_test.go +++ b/rados/rados_test.go @@ -436,3 +436,8 @@ func TestObjectIterator(t *testing.T) { assert.Equal(t, objectList, createdList) } + +func TestNewConnWithUser(t *testing.T) { + _, err := rados.NewConnWithUser("admin") + assert.Equal(t, err, nil) +}