Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bindings/c/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
build/
docs/
docs/

*.o
1 change: 1 addition & 0 deletions bindings/c/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
basicrw
1 change: 1 addition & 0 deletions bindings/go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
opendal_c.pc
55 changes: 55 additions & 0 deletions bindings/go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# OpenDAL Go Binding (WIP)

opendal-go requires opendal-c to be installed.

```shell
cd bindings/c
make build
```

You will find `libopendal_c.so` under `{root}/target`.

Then, we need to add a `opendal_c.pc` files

```pc
libdir=/path/to/opendal/target/debug/
includedir=/path/to/opendal/bindings/c/include/

Name: opendal_c
Description: opendal c binding
Version:

Libs: -L${libdir} -lopendal_c
Cflags: -I${includedir}
```

And set the `PKG_CONFIG_PATH` environment variable to the directory where `opendal_c.pc` is located.

```shell
export PKG_CONFIG_PATH=/dir/of/opendal_c.pc
```

Then, we can build the go binding.

```shell
cd bindings/go
go build -tags dynamic .
```

To running the go binding tests, we need to tell the linker where to find the `libopendal_c.so` file.

```shell
expose LD_LIBRARY_PATH=/path/to/opendal/target/debug/
```

Then, we can run the tests.

```shell
go test -tags dynamic .
```

For benchmark

```shell
go test -bench=. -tags dynamic .
```
1 change: 0 additions & 1 deletion bindings/go/opendal.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type Operator struct {
}

func NewOperator(scheme string, opt Options) (*Operator, error) {
fmt.Println("libopendal_c info: ", LibopendalLinkInfo)
if len(scheme) == 0 {
return nil, errInvalidScheme
}
Expand Down
23 changes: 21 additions & 2 deletions bindings/go/opendal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package opendal

import (
"bytes"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -31,9 +32,27 @@ func TestOperations(t *testing.T) {
operator, err := NewOperator("memory", opts)
assert.NoError(t, err)
defer operator.Close()
err = operator.Write("test", []byte("Hello World"))
err = operator.Write("test", []byte("Hello World from OpenDAL CGO!"))
assert.NoError(t, err)
value, err := operator.Read("test")
assert.NoError(t, err)
assert.Equal(t, "Hello World", string(value))
assert.Equal(t, "Hello World from OpenDAL CGO!", string(value))

println(string(value))
}

func BenchmarkOperator_Write(b *testing.B) {
opts := make(Options)
opts["root"] = "/myroot"
op, _ := NewOperator("memory", opts)
defer op.Close()

bs := bytes.Repeat([]byte("a"), 1024*1024)
op.Write("test", bs)

b.SetBytes(1024*1024)
b.ResetTimer()
for i := 0; i < b.N; i++ {
op.Read("test")
}
}