You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by de...@apache.org on 2026/06/11 00:27:51 UTC
(opendal) branch main updated: feat(operator.go): use c binding check (#7724)
This is an automated email from the ASF dual-hosted git repository.
dentiny pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new fdc29bcd3 feat(operator.go): use c binding check (#7724)
fdc29bcd3 is described below
commit fdc29bcd322c23ba4562d503bb44cc610104dcfc
Author: PoAn Yang <pa...@apache.org>
AuthorDate: Thu Jun 11 09:27:46 2026 +0900
feat(operator.go): use c binding check (#7724)
---
bindings/go/lister.go | 46 ----------------------------------------------
bindings/go/operator.go | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 46 deletions(-)
diff --git a/bindings/go/lister.go b/bindings/go/lister.go
index 8a3fd9bb2..316c3f6b0 100644
--- a/bindings/go/lister.go
+++ b/bindings/go/lister.go
@@ -26,52 +26,6 @@ import (
"github.com/jupiterrider/ffi"
)
-// Check verifies if the operator is functioning correctly.
-//
-// This function performs a health check on the operator by sending a `list` request
-// to the root path. It returns any errors encountered during this process.
-//
-// # Returns
-//
-// - error: An error if the check fails, or nil if the operator is working correctly.
-//
-// # Details
-//
-// The check is performed by attempting to list the contents of the root directory.
-// This operation tests the basic functionality of the operator, including
-// connectivity and permissions.
-//
-// # Example
-//
-// func exampleCheck(op *opendal.Operator) {
-// err = op.Check()
-// if err != nil {
-// log.Printf("Operator check failed: %v", err)
-// } else {
-// log.Println("Operator is functioning correctly")
-// }
-// }
-//
-// Note: This example assumes proper error handling and import statements.
-func (op *Operator) Check() (err error) {
- ds, err := op.List("/")
- if err != nil {
- return
- }
- defer func() {
- closeErr := ds.Close()
- if err == nil {
- err = closeErr
- }
- }()
- ds.Next()
- err = ds.Error()
- if err, ok := err.(*Error); ok && err.Code() == CodeNotFound {
- return nil
- }
- return
-}
-
// List returns a Lister to iterate over entries that start with the given path in the parent directory.
//
// WithListFn is a functional option for the List operation.
diff --git a/bindings/go/operator.go b/bindings/go/operator.go
index ac0094494..5bb31374b 100644
--- a/bindings/go/operator.go
+++ b/bindings/go/operator.go
@@ -62,6 +62,32 @@ func (op *Operator) Rename(src, dest string) error {
return ffiOperatorRename.symbol(op.ctx)(op.inner, src, dest)
}
+// Check verifies if the operator is functioning correctly.
+//
+// Check is a wrapper around the C-binding function `opendal_operator_check`.
+// It performs a health check against the underlying backend, returning any
+// error encountered while reaching it.
+//
+// # Returns
+//
+// - error: An error if the check fails, or nil if the operator is working correctly.
+//
+// # Example
+//
+// func exampleCheck(op *opendal.Operator) {
+// err = op.Check()
+// if err != nil {
+// log.Printf("Operator check failed: %v", err)
+// } else {
+// log.Println("Operator is functioning correctly")
+// }
+// }
+//
+// Note: This example assumes proper error handling and import statements.
+func (op *Operator) Check() error {
+ return ffiOperatorCheck.symbol(op.ctx)(op.inner)
+}
+
func normalizeScheme(scheme Scheme) (*byte, error) {
return BytePtrFromString(strings.ReplaceAll(scheme.Name(), "_", "-"))
}
@@ -217,6 +243,21 @@ var ffiOperatorRename = newFFI(ffiOpts{
}
})
+var ffiOperatorCheck = newFFI(ffiOpts{
+ sym: "opendal_operator_check",
+ rType: &ffi.TypePointer,
+ aTypes: []*ffi.Type{&ffi.TypePointer},
+}, func(ctx context.Context, ffiCall ffiCall) func(op *opendalOperator) error {
+ return func(op *opendalOperator) error {
+ var e *opendalError
+ ffiCall(
+ unsafe.Pointer(&e),
+ unsafe.Pointer(&op),
+ )
+ return parseError(ctx, e)
+ }
+})
+
var ffiBytesFree = newFFI(ffiOpts{
sym: "opendal_bytes_free",
rType: &ffi.TypeVoid,