You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/09/28 10:05:09 UTC

[incubator-opendal] branch basic-readme created (now 2793c71b3)

This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a change to branch basic-readme
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


      at 2793c71b3 docs: Add basic readme for go binding

This branch includes the following new commits:

     new 2793c71b3 docs: Add basic readme for go binding

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-opendal] 01/01: docs: Add basic readme for go binding

Posted by xu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch basic-readme
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git

commit 2793c71b31ee27d5e572f64087280e16d7021ddf
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Thu Sep 28 18:04:55 2023 +0800

    docs: Add basic readme for go binding
    
    Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
 bindings/c/.gitignore          |  4 ++-
 bindings/c/examples/.gitignore |  1 +
 bindings/go/.gitignore         |  1 +
 bindings/go/README.md          | 55 ++++++++++++++++++++++++++++++++++++++++++
 bindings/go/opendal.go         |  1 -
 bindings/go/opendal_test.go    | 23 ++++++++++++++++--
 6 files changed, 81 insertions(+), 4 deletions(-)

diff --git a/bindings/c/.gitignore b/bindings/c/.gitignore
index c4ec047b9..8f5beed0e 100644
--- a/bindings/c/.gitignore
+++ b/bindings/c/.gitignore
@@ -1,2 +1,4 @@
 build/
-docs/
\ No newline at end of file
+docs/
+
+*.o
diff --git a/bindings/c/examples/.gitignore b/bindings/c/examples/.gitignore
new file mode 100644
index 000000000..887b0251a
--- /dev/null
+++ b/bindings/c/examples/.gitignore
@@ -0,0 +1 @@
+basicrw
diff --git a/bindings/go/.gitignore b/bindings/go/.gitignore
new file mode 100644
index 000000000..c79b32353
--- /dev/null
+++ b/bindings/go/.gitignore
@@ -0,0 +1 @@
+opendal_c.pc
diff --git a/bindings/go/README.md b/bindings/go/README.md
new file mode 100644
index 000000000..352a0749c
--- /dev/null
+++ b/bindings/go/README.md
@@ -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 .
+```
diff --git a/bindings/go/opendal.go b/bindings/go/opendal.go
index 45f6b2f05..1494ab170 100644
--- a/bindings/go/opendal.go
+++ b/bindings/go/opendal.go
@@ -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
 	}
diff --git a/bindings/go/opendal_test.go b/bindings/go/opendal_test.go
index 30b50bd94..6723b67e2 100644
--- a/bindings/go/opendal_test.go
+++ b/bindings/go/opendal_test.go
@@ -20,6 +20,7 @@
 package opendal
 
 import (
+	"bytes"
 	"testing"
 
 	"github.com/stretchr/testify/assert"
@@ -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")
+	}
 }