From 1a3417f83f021dea3dd5a85b4bd7bc13e4bdfb6a Mon Sep 17 00:00:00 2001 From: Hanchin Hsieh Date: Tue, 27 Aug 2024 14:27:50 +0800 Subject: [PATCH] ci(bindings/go): add golangci-lint (#5060) Signed-off-by: Hanchin Hsieh --- .github/workflows/ci_bindings_go.yml | 16 ++++++++++++++++ bindings/go/ffi.go | 13 ++++++++++--- bindings/go/opendal.go | 8 ++++++-- bindings/go/operator.go | 4 +--- bindings/go/types.go | 24 ++++++------------------ 5 files changed, 39 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci_bindings_go.yml b/.github/workflows/ci_bindings_go.yml index bb975fce4f0d..bde9e0cb2d84 100644 --- a/.github/workflows/ci_bindings_go.yml +++ b/.github/workflows/ci_bindings_go.yml @@ -39,9 +39,23 @@ concurrency: permissions: contents: read + pull-requests: read + checks: write jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: stable + - uses: golangci/golangci-lint-action@v6 + with: + version: "v1.60" + working-directory: bindings/go matrix: + needs: [ lint ] runs-on: ubuntu-latest outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} @@ -73,6 +87,8 @@ jobs: TARGET: ${{ matrix.build.target }} run: rustup target add $TARGET - uses: actions/setup-go@v5 + with: + go-version: stable - uses: actions/setup-python@v5 with: python-version: "3.10" diff --git a/bindings/go/ffi.go b/bindings/go/ffi.go index 802ae48582d4..8d5f2d58443f 100644 --- a/bindings/go/ffi.go +++ b/bindings/go/ffi.go @@ -49,11 +49,18 @@ func contextWithFFIs(path string) (ctx context.Context, cancel context.CancelFun type contextWithFFI func(ctx context.Context, libopendal uintptr) (context.Context, error) func getFFI[T any](ctx context.Context, key string) T { - return ctx.Value(key).(T) + ctxKey := contextKey(key) + return ctx.Value(ctxKey).(T) +} + +type contextKey string + +func (k contextKey) String() string { + return string(k) } type ffiOpts struct { - sym string + sym contextKey rType *ffi.Type aTypes []*ffi.Type } @@ -76,7 +83,7 @@ func withFFI[T any]( ); status != ffi.OK { return nil, errors.New(status.String()) } - fn, err := purego.Dlsym(libopendal, opts.sym) + fn, err := purego.Dlsym(libopendal, opts.sym.String()) if err != nil { return nil, err } diff --git a/bindings/go/opendal.go b/bindings/go/opendal.go index eeb7231c13f2..86b80b853601 100644 --- a/bindings/go/opendal.go +++ b/bindings/go/opendal.go @@ -180,10 +180,14 @@ func NewOperator(scheme Scheme, opts OperatorOptions) (op *Operator, err error) setOptions := getFFI[operatorOptionsSet](ctx, symOperatorOptionSet) optionsFree := getFFI[operatorOptionsFree](ctx, symOperatorOptionsFree) + defer optionsFree(options) + for key, value := range opts { - setOptions(options, key, value) + err = setOptions(options, key, value) + if err != nil { + return + } } - defer optionsFree(options) inner, err := getFFI[operatorNew](ctx, symOperatorNew)(scheme, options) if err != nil { diff --git a/bindings/go/operator.go b/bindings/go/operator.go index feb841e3ecc3..d63bacda61ee 100644 --- a/bindings/go/operator.go +++ b/bindings/go/operator.go @@ -147,9 +147,7 @@ var withOperatorFree = withFFI(ffiOpts{ } }) -type operatorOptions struct { - inner uintptr -} +type operatorOptions struct{} const symOperatorOptionsNew = "opendal_operator_options_new" diff --git a/bindings/go/types.go b/bindings/go/types.go index 9fe21597234d..49c0daf5d3f8 100644 --- a/bindings/go/types.go +++ b/bindings/go/types.go @@ -195,18 +195,14 @@ type resultOperatorNew struct { error *opendalError } -type opendalOperator struct { - ptr uintptr -} +type opendalOperator struct{} type resultRead struct { data *opendalBytes error *opendalError } -type opendalReader struct { - inner uintptr -} +type opendalReader struct{} type resultOperatorReader struct { reader *opendalReader @@ -228,9 +224,7 @@ type resultStat struct { error *opendalError } -type opendalMetadata struct { - inner uintptr -} +type opendalMetadata struct{} type opendalBytes struct { data *byte @@ -242,27 +236,21 @@ type opendalError struct { message opendalBytes } -type opendalOperatorInfo struct { - inner uintptr -} +type opendalOperatorInfo struct{} type opendalResultList struct { lister *opendalLister err *opendalError } -type opendalLister struct { - inner uintptr -} +type opendalLister struct{} type opendalResultListerNext struct { entry *opendalEntry err *opendalError } -type opendalEntry struct { - inner uintptr -} +type opendalEntry struct{} func toOpendalBytes(data []byte) opendalBytes { var ptr *byte