-
Notifications
You must be signed in to change notification settings - Fork 740
feat: Add golang binding for OpenDAL #2488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # OpenDAL Golang Binding | ||
|
|
||
| Build C binding first. | ||
|
|
||
| cd `bindings/c` | ||
|
|
||
| ```shell | ||
| cargo build | ||
| ``` | ||
|
|
||
| and than cd `bindings/go` | ||
|
|
||
| ```shell | ||
| CGO_ENABLED=0 LD_LIBRARY_PATH=../../target/debug go test -v | ||
| ``` | ||
|
|
||
| We can call it without CGO (only work under linux). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| module opendal.apache.org/go | ||
|
|
||
| go 1.20 | ||
|
|
||
| require github.com/ebitengine/purego v0.4.0-alpha.4 | ||
|
Xuanwo marked this conversation as resolved.
|
||
|
|
||
| require golang.org/x/sys v0.7.0 // indirect | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| github.com/ebitengine/purego v0.4.0-alpha.4 h1:Y7yIV06Yo5M2BAdD7EVPhfp6LZ0tEcQo5770OhYUVes= | ||
| github.com/ebitengine/purego v0.4.0-alpha.4/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ= | ||
| golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= | ||
| golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package opendal | ||
|
|
||
| import ( | ||
| "github.com/ebitengine/purego" | ||
| ) | ||
|
|
||
| var OPENDAL_LIB uintptr | ||
|
|
||
| var opendal_operator_options_new func() uintptr | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @Ji-Xinyou, I will meet
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can try to fix that now |
||
| var opendal_operator_new func(uintptr) uintptr | ||
|
|
||
| func init() { | ||
| var err error | ||
| OPENDAL_LIB, err = openLibrary() | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| purego.RegisterLibFunc(&opendal_operator_options_new, OPENDAL_LIB, "opendal_operator_options_new") | ||
| purego.RegisterLibFunc(&opendal_operator_new, OPENDAL_LIB, "opendal_operator_new") | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| //go:build linux | ||
|
|
||
| package opendal | ||
|
|
||
| import "github.com/ebitengine/purego" | ||
|
|
||
| func openLibrary() (uintptr, error) { | ||
| return purego.Dlopen("libopendal_c.so", purego.RTLD_NOW|purego.RTLD_GLOBAL) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package opendal | ||
|
|
||
| import "unsafe" | ||
|
|
||
| type Operator struct { | ||
| op uintptr | ||
| } | ||
|
|
||
| func NewOperator(scheme string) *Operator { | ||
| trick := append([]byte(scheme), 0) | ||
| op := opendal_operator_new(uintptr(unsafe.Pointer(&trick[0]))) | ||
|
|
||
| return &Operator{ | ||
| op: op, | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package opendal | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestNew(t *testing.T) { | ||
| op := NewOperator("memory") | ||
| t.Logf("%v", op) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.