Skip to content

Commit

Permalink
ci(bindings/go): add golangci-lint (#5060)
Browse files Browse the repository at this point in the history
Signed-off-by: Hanchin Hsieh <me@yuchanns.xyz>
  • Loading branch information
yuchanns authored Aug 27, 2024
1 parent 8bc883f commit 1a3417f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci_bindings_go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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"
Expand Down
13 changes: 10 additions & 3 deletions bindings/go/ffi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
8 changes: 6 additions & 2 deletions bindings/go/opendal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions bindings/go/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ var withOperatorFree = withFFI(ffiOpts{
}
})

type operatorOptions struct {
inner uintptr
}
type operatorOptions struct{}

const symOperatorOptionsNew = "opendal_operator_options_new"

Expand Down
24 changes: 6 additions & 18 deletions bindings/go/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -228,9 +224,7 @@ type resultStat struct {
error *opendalError
}

type opendalMetadata struct {
inner uintptr
}
type opendalMetadata struct{}

type opendalBytes struct {
data *byte
Expand All @@ -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
Expand Down

0 comments on commit 1a3417f

Please sign in to comment.