Added NewConnWithUser to allow users other than the default

This commit is contained in:
Dusty Wilson 2015-02-22 02:54:06 -08:00
parent e703215356
commit 9c7193f3ad
1 changed files with 17 additions and 0 deletions

View File

@ -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))
}
}