Merge pull request #23 from theanalyst/wip-gofmt

go fmt the source files and add travis check for go fmt
This commit is contained in:
Noah Watkins 2015-07-12 14:23:37 -06:00
commit 8f882afdc3
6 changed files with 187 additions and 187 deletions

View File

@ -20,6 +20,7 @@ before_install:
script:
- go get -t -v ./...
- go test -v ./...
- go fmt ./...
notifications:
recipients:

View File

@ -14,76 +14,76 @@ import "unsafe"
type CephError int
func (e CephError) Error() string {
return fmt.Sprintf("cephfs: ret=%d", e)
return fmt.Sprintf("cephfs: ret=%d", e)
}
//
type MountInfo struct {
mount *C.struct_ceph_mount_info
mount *C.struct_ceph_mount_info
}
func CreateMount() (*MountInfo, error) {
mount := &MountInfo{}
ret := C.ceph_create(&mount.mount, nil)
if ret == 0 {
return mount, nil
} else {
return nil, CephError(ret)
}
mount := &MountInfo{}
ret := C.ceph_create(&mount.mount, nil)
if ret == 0 {
return mount, nil
} else {
return nil, CephError(ret)
}
}
func (mount *MountInfo) ReadDefaultConfigFile() error {
ret := C.ceph_conf_read_file(mount.mount, nil)
if ret == 0 {
return nil
} else {
return CephError(ret)
}
ret := C.ceph_conf_read_file(mount.mount, nil)
if ret == 0 {
return nil
} else {
return CephError(ret)
}
}
func (mount *MountInfo) Mount() error {
ret := C.ceph_mount(mount.mount, nil)
if ret == 0 {
return nil
} else {
return CephError(ret)
}
ret := C.ceph_mount(mount.mount, nil)
if ret == 0 {
return nil
} else {
return CephError(ret)
}
}
func (mount *MountInfo) SyncFs() error {
ret := C.ceph_sync_fs(mount.mount)
if ret == 0 {
return nil
} else {
return CephError(ret)
}
ret := C.ceph_sync_fs(mount.mount)
if ret == 0 {
return nil
} else {
return CephError(ret)
}
}
func (mount *MountInfo) CurrentDir() string {
c_dir := C.ceph_getcwd(mount.mount)
return C.GoString(c_dir)
c_dir := C.ceph_getcwd(mount.mount)
return C.GoString(c_dir)
}
func (mount *MountInfo) ChangeDir(path string) error {
c_path := C.CString(path)
defer C.free(unsafe.Pointer(c_path))
c_path := C.CString(path)
defer C.free(unsafe.Pointer(c_path))
ret := C.ceph_chdir(mount.mount, c_path)
if ret == 0 {
return nil
} else {
return CephError(ret)
}
ret := C.ceph_chdir(mount.mount, c_path)
if ret == 0 {
return nil
} else {
return CephError(ret)
}
}
func (mount *MountInfo) MakeDir(path string, mode uint32) error {
c_path := C.CString(path)
defer C.free(unsafe.Pointer(c_path))
c_path := C.CString(path)
defer C.free(unsafe.Pointer(c_path))
ret := C.ceph_mkdir(mount.mount, c_path, C.mode_t(mode))
if ret == 0 {
return nil
} else {
return CephError(ret)
}
ret := C.ceph_mkdir(mount.mount, c_path, C.mode_t(mode))
if ret == 0 {
return nil
} else {
return CephError(ret)
}
}

View File

@ -5,62 +5,62 @@ import "github.com/noahdesu/go-ceph/cephfs"
import "github.com/stretchr/testify/assert"
func TestCreateMount(t *testing.T) {
mount, err := cephfs.CreateMount()
assert.NoError(t, err)
assert.NotNil(t, mount)
mount, err := cephfs.CreateMount()
assert.NoError(t, err)
assert.NotNil(t, mount)
}
func TestMountRoot(t *testing.T) {
mount, err := cephfs.CreateMount()
assert.NoError(t, err)
assert.NotNil(t, mount)
mount, err := cephfs.CreateMount()
assert.NoError(t, err)
assert.NotNil(t, mount)
err = mount.ReadDefaultConfigFile()
assert.NoError(t, err)
err = mount.ReadDefaultConfigFile()
assert.NoError(t, err)
err = mount.Mount()
assert.NoError(t, err)
err = mount.Mount()
assert.NoError(t, err)
}
func TestSyncFs(t *testing.T) {
mount, err := cephfs.CreateMount()
assert.NoError(t, err)
assert.NotNil(t, mount)
mount, err := cephfs.CreateMount()
assert.NoError(t, err)
assert.NotNil(t, mount)
err = mount.ReadDefaultConfigFile()
assert.NoError(t, err)
err = mount.ReadDefaultConfigFile()
assert.NoError(t, err)
err = mount.Mount()
assert.NoError(t, err)
err = mount.Mount()
assert.NoError(t, err)
err = mount.SyncFs()
assert.NoError(t, err)
err = mount.SyncFs()
assert.NoError(t, err)
}
func TestChangeDir(t *testing.T) {
mount, err := cephfs.CreateMount()
assert.NoError(t, err)
assert.NotNil(t, mount)
mount, err := cephfs.CreateMount()
assert.NoError(t, err)
assert.NotNil(t, mount)
err = mount.ReadDefaultConfigFile()
assert.NoError(t, err)
err = mount.ReadDefaultConfigFile()
assert.NoError(t, err)
err = mount.Mount()
assert.NoError(t, err)
err = mount.Mount()
assert.NoError(t, err)
dir1 := mount.CurrentDir()
assert.NotNil(t, dir1)
dir1 := mount.CurrentDir()
assert.NotNil(t, dir1)
err = mount.MakeDir("/asdf", 0755)
assert.NoError(t, err)
err = mount.MakeDir("/asdf", 0755)
assert.NoError(t, err)
err = mount.ChangeDir("/asdf")
assert.NoError(t, err)
err = mount.ChangeDir("/asdf")
assert.NoError(t, err)
dir2 := mount.CurrentDir()
assert.NotNil(t, dir2)
dir2 := mount.CurrentDir()
assert.NotNil(t, dir2)
assert.NotEqual(t, dir1, dir2)
assert.Equal(t, dir1, "/")
assert.Equal(t, dir2, "/asdf")
assert.NotEqual(t, dir1, dir2)
assert.Equal(t, dir1, "/")
assert.Equal(t, dir2, "/asdf")
}

View File

@ -35,9 +35,9 @@ type PoolStat struct {
// ObjectStat represents an object stat information
type ObjectStat struct {
// current length in bytes
Size uint64
Size uint64
// last modification time
ModTime time.Time
ModTime time.Time
}
// IOContext represents a context for performing I/O within a pool.
@ -218,7 +218,7 @@ func (ioctx *IOContext) Stat(object string) (stat ObjectStat, err error) {
return ObjectStat{}, RadosError(int(ret))
} else {
return ObjectStat{
Size: uint64(c_psize),
Size: uint64(c_psize),
ModTime: time.Unix(int64(c_pmtime), 0),
}, nil
}
@ -322,62 +322,62 @@ func (ioctx *IOContext) RmXattr(oid string, name string) error {
// Append the map `pairs` to the omap `oid`
func (ioctx *IOContext) SetOmap(oid string, pairs map[string][]byte) error {
c_oid := C.CString(oid)
defer C.free(unsafe.Pointer(c_oid))
c_oid := C.CString(oid)
defer C.free(unsafe.Pointer(c_oid))
var s C.size_t
var c *C.char
ptrSize := unsafe.Sizeof(c)
var s C.size_t
var c *C.char
ptrSize := unsafe.Sizeof(c)
c_keys := C.malloc(C.size_t(len(pairs)) * C.size_t(ptrSize))
c_values := C.malloc(C.size_t(len(pairs)) * C.size_t(ptrSize))
c_lengths := C.malloc(C.size_t(len(pairs)) * C.size_t(unsafe.Sizeof(s)))
c_keys := C.malloc(C.size_t(len(pairs)) * C.size_t(ptrSize))
c_values := C.malloc(C.size_t(len(pairs)) * C.size_t(ptrSize))
c_lengths := C.malloc(C.size_t(len(pairs)) * C.size_t(unsafe.Sizeof(s)))
defer C.free(unsafe.Pointer(c_keys))
defer C.free(unsafe.Pointer(c_values))
defer C.free(unsafe.Pointer(c_lengths))
defer C.free(unsafe.Pointer(c_keys))
defer C.free(unsafe.Pointer(c_values))
defer C.free(unsafe.Pointer(c_lengths))
i := 0
for key, value := range pairs {
// key
c_key_ptr := (**C.char)(unsafe.Pointer(uintptr(c_keys) + uintptr(i) * ptrSize))
*c_key_ptr = C.CString(key)
defer C.free(unsafe.Pointer(*c_key_ptr))
i := 0
for key, value := range pairs {
// key
c_key_ptr := (**C.char)(unsafe.Pointer(uintptr(c_keys) + uintptr(i)*ptrSize))
*c_key_ptr = C.CString(key)
defer C.free(unsafe.Pointer(*c_key_ptr))
// value and its length
c_value_ptr := (**C.char)(unsafe.Pointer(uintptr(c_values) + uintptr(i) * ptrSize))
// value and its length
c_value_ptr := (**C.char)(unsafe.Pointer(uintptr(c_values) + uintptr(i)*ptrSize))
var c_length C.size_t
if len(value) > 0 {
*c_value_ptr = (*C.char)(unsafe.Pointer(&value[0]))
c_length = C.size_t(len(value))
} else {
*c_value_ptr = nil
c_length = C.size_t(0)
}
var c_length C.size_t
if len(value) > 0 {
*c_value_ptr = (*C.char)(unsafe.Pointer(&value[0]))
c_length = C.size_t(len(value))
} else {
*c_value_ptr = nil
c_length = C.size_t(0)
}
c_length_ptr := (*C.size_t)(unsafe.Pointer(uintptr(c_lengths) + uintptr(i) * ptrSize))
*c_length_ptr = c_length
c_length_ptr := (*C.size_t)(unsafe.Pointer(uintptr(c_lengths) + uintptr(i)*ptrSize))
*c_length_ptr = c_length
i++
}
i++
}
op := C.rados_create_write_op()
C.rados_write_op_omap_set(
op,
(**C.char)(c_keys),
(**C.char)(c_values),
(*C.size_t)(c_lengths),
C.size_t(len(pairs)))
op := C.rados_create_write_op()
C.rados_write_op_omap_set(
op,
(**C.char)(c_keys),
(**C.char)(c_values),
(*C.size_t)(c_lengths),
C.size_t(len(pairs)))
ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0)
C.rados_release_write_op(op)
ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0)
C.rados_release_write_op(op)
if ret == 0 {
return nil
} else {
return RadosError(int(ret))
}
if ret == 0 {
return nil
} else {
return RadosError(int(ret))
}
}
// OmapListFunc is the type of the function called for each omap key
@ -472,7 +472,7 @@ func (ioctx *IOContext) GetAllOmapValues(oid string, startAfter string, filterPr
for {
err := ioctx.ListOmapValues(
oid, startAfter, filterPrefix, iteratorSize,
func (key string, value []byte) {
func(key string, value []byte) {
omap[key] = value
startAfter = key
},
@ -495,53 +495,53 @@ func (ioctx *IOContext) GetAllOmapValues(oid string, startAfter string, filterPr
// Remove the specified `keys` from the omap `oid`
func (ioctx *IOContext) RmOmapKeys(oid string, keys []string) error {
c_oid := C.CString(oid)
defer C.free(unsafe.Pointer(c_oid))
c_oid := C.CString(oid)
defer C.free(unsafe.Pointer(c_oid))
var c *C.char
ptrSize := unsafe.Sizeof(c)
var c *C.char
ptrSize := unsafe.Sizeof(c)
c_keys := C.malloc(C.size_t(len(keys)) * C.size_t(ptrSize))
defer C.free(unsafe.Pointer(c_keys))
c_keys := C.malloc(C.size_t(len(keys)) * C.size_t(ptrSize))
defer C.free(unsafe.Pointer(c_keys))
i := 0
for _, key := range keys {
c_key_ptr := (**C.char)(unsafe.Pointer(uintptr(c_keys) + uintptr(i) * ptrSize))
*c_key_ptr = C.CString(key)
defer C.free(unsafe.Pointer(*c_key_ptr))
i++
}
i := 0
for _, key := range keys {
c_key_ptr := (**C.char)(unsafe.Pointer(uintptr(c_keys) + uintptr(i)*ptrSize))
*c_key_ptr = C.CString(key)
defer C.free(unsafe.Pointer(*c_key_ptr))
i++
}
op := C.rados_create_write_op()
C.rados_write_op_omap_rm_keys(
op,
(**C.char)(c_keys),
C.size_t(len(keys)))
op := C.rados_create_write_op()
C.rados_write_op_omap_rm_keys(
op,
(**C.char)(c_keys),
C.size_t(len(keys)))
ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0)
C.rados_release_write_op(op)
ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0)
C.rados_release_write_op(op)
if ret == 0 {
return nil
} else {
return RadosError(int(ret))
}
if ret == 0 {
return nil
} else {
return RadosError(int(ret))
}
}
// Clear the omap `oid`
func (ioctx *IOContext) CleanOmap(oid string) error {
c_oid := C.CString(oid)
defer C.free(unsafe.Pointer(c_oid))
c_oid := C.CString(oid)
defer C.free(unsafe.Pointer(c_oid))
op := C.rados_create_write_op()
C.rados_write_op_omap_clear(op)
op := C.rados_create_write_op()
C.rados_write_op_omap_clear(op)
ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0)
C.rados_release_write_op(op)
ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0)
C.rados_release_write_op(op)
if ret == 0 {
return nil
} else {
return RadosError(int(ret))
}
if ret == 0 {
return nil
} else {
return RadosError(int(ret))
}
}

View File

@ -53,7 +53,7 @@ func NewConnWithUser(user string) (*Conn, error) {
}
}
// NewConnWithClusterAndUser creates a new connection object for a specific cluster and username.
// NewConnWithClusterAndUser creates a new connection object for a specific cluster and username.
// It returns the connection and an error, if any.
func NewConnWithClusterAndUser(clusterName string, userName string) (*Conn, error) {
c_cluster_name := C.CString(clusterName)

View File

@ -601,10 +601,10 @@ func TestReadWriteOmap(t *testing.T) {
// Set
orig := map[string][]byte{
"key1": []byte("value1"),
"key2": []byte("value2"),
"prefixed-key3": []byte("value3"),
"empty": []byte(""),
"key1": []byte("value1"),
"key2": []byte("value2"),
"prefixed-key3": []byte("value3"),
"empty": []byte(""),
}
err = pool.SetOmap("obj", orig)
@ -624,17 +624,17 @@ func TestReadWriteOmap(t *testing.T) {
assert.Equal(t, 0, len(remaining))
// Get (with a fixed number of keys)
fetched, err := pool.GetOmapValues("obj", "", "", 4)
fetched, err := pool.GetOmapValues("obj", "", "", 4)
assert.NoError(t, err)
assert.Equal(t, orig, fetched)
// Get All (with an iterator size bigger than the map size)
fetched, err = pool.GetAllOmapValues("obj", "", "", 100)
fetched, err = pool.GetAllOmapValues("obj", "", "", 100)
assert.NoError(t, err)
assert.Equal(t, orig, fetched)
// Get All (with an iterator size smaller than the map size)
fetched, err = pool.GetAllOmapValues("obj", "", "", 1)
fetched, err = pool.GetAllOmapValues("obj", "", "", 1)
assert.NoError(t, err)
assert.Equal(t, orig, fetched)
@ -642,18 +642,18 @@ func TestReadWriteOmap(t *testing.T) {
err = pool.RmOmapKeys("obj", []string{"key1", "prefixed-key3"})
assert.NoError(t, err)
fetched, err = pool.GetOmapValues("obj", "", "", 4)
fetched, err = pool.GetOmapValues("obj", "", "", 4)
assert.NoError(t, err)
assert.Equal(t, map[string][]byte{
"key2": []byte("value2"),
"empty": []byte(""),
"key2": []byte("value2"),
"empty": []byte(""),
}, fetched)
// Clear
err = pool.CleanOmap("obj")
assert.NoError(t, err)
fetched, err = pool.GetOmapValues("obj", "", "", 4)
fetched, err = pool.GetOmapValues("obj", "", "", 4)
assert.NoError(t, err)
assert.Equal(t, map[string][]byte{}, fetched)
@ -673,9 +673,9 @@ func TestReadFilterOmap(t *testing.T) {
assert.NoError(t, err)
orig := map[string][]byte{
"key1": []byte("value1"),
"prefixed-key3": []byte("value3"),
"key2": []byte("value2"),
"key1": []byte("value1"),
"prefixed-key3": []byte("value3"),
"key2": []byte("value2"),
}
err = pool.SetOmap("obj", orig)
@ -685,24 +685,23 @@ func TestReadFilterOmap(t *testing.T) {
fetched, err := pool.GetOmapValues("obj", "", "prefixed", 4)
assert.NoError(t, err)
assert.Equal(t, map[string][]byte{
"prefixed-key3": []byte("value3"),
"prefixed-key3": []byte("value3"),
}, fetched)
// "start_after" a key
fetched, err = pool.GetOmapValues("obj", "key1", "", 4)
assert.NoError(t, err)
assert.Equal(t, map[string][]byte{
"prefixed-key3": []byte("value3"),
"key2": []byte("value2"),
"prefixed-key3": []byte("value3"),
"key2": []byte("value2"),
}, fetched)
// maxReturn
fetched, err = pool.GetOmapValues("obj", "", "key", 1)
assert.NoError(t, err)
assert.Equal(t, map[string][]byte{
"key1": []byte("value1"),
"key1": []byte("value1"),
}, fetched)
pool.Destroy()
}