2014-05-24 17:36:12 +00:00
|
|
|
package rados
|
|
|
|
|
|
|
|
// #cgo LDFLAGS: -lrados
|
|
|
|
// #include <stdlib.h>
|
|
|
|
// #include <rados/librados.h>
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
2015-02-11 21:21:05 +00:00
|
|
|
"fmt"
|
2015-02-22 10:54:06 +00:00
|
|
|
"unsafe"
|
2014-05-24 17:36:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type RadosError int
|
|
|
|
|
|
|
|
func (e RadosError) Error() string {
|
2015-02-11 21:21:05 +00:00
|
|
|
return fmt.Sprintf("rados: ret=%d", e)
|
2014-05-24 17:36:12 +00:00
|
|
|
}
|
|
|
|
|
2014-05-24 18:42:18 +00:00
|
|
|
// Version returns the major, minor, and patch components of the version of
|
|
|
|
// the RADOS library linked against.
|
2014-05-24 17:36:12 +00:00
|
|
|
func Version() (int, int, int) {
|
2015-02-11 21:21:05 +00:00
|
|
|
var c_major, c_minor, c_patch C.int
|
|
|
|
C.rados_version(&c_major, &c_minor, &c_patch)
|
|
|
|
return int(c_major), int(c_minor), int(c_patch)
|
2014-05-24 17:36:12 +00:00
|
|
|
}
|
|
|
|
|
2014-05-24 18:42:18 +00:00
|
|
|
// NewConn creates a new connection object. It returns the connection and an
|
|
|
|
// error, if any.
|
|
|
|
func NewConn() (*Conn, error) {
|
2015-02-11 21:21:05 +00:00
|
|
|
conn := &Conn{}
|
|
|
|
ret := C.rados_create(&conn.cluster, nil)
|
2014-05-24 17:36:12 +00:00
|
|
|
|
2015-02-11 21:21:05 +00:00
|
|
|
if ret == 0 {
|
|
|
|
return conn, nil
|
|
|
|
} else {
|
|
|
|
return nil, RadosError(int(ret))
|
|
|
|
}
|
2014-05-24 17:36:12 +00:00
|
|
|
}
|
2015-02-22 10:54:06 +00:00
|
|
|
|
|
|
|
// 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))
|
|
|
|
}
|
|
|
|
}
|