Skip to content

Commit

Permalink
fix(client): cgo problem
Browse files Browse the repository at this point in the history
  • Loading branch information
bububa committed Nov 15, 2023
1 parent 2d5ca8e commit 2a30ca3
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 47 deletions.
38 changes: 29 additions & 9 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
name: Go
on: [push, pull_request]

on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]

jobs:

build:
runs-on: ubuntu-latest
env:
GOPATH: ${{ github.workspace }}
package: src/github.com/${{ github.repository }}
defaults:
run:
working-directory: ${{ env.GOPATH }}/${{ env.package }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
path: ${{ env.GOPATH }}/${{ env.package }}

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.16
go-version: '1.18'
cache-dependency-path: |
${{ env.GOPATH }}/${{ env.package }}/go.mod
${{ env.GOPATH }}/${{ env.package }}/go.sum
- name: Dependencies
run: go mod download

- name: Build
env:
CGO_LDFLAGS_ALLOW: '-w'
run: go build -v --ldflags '-L./lib' ./...
working-directory: ${{ env.GOPATH }}/${{ env.package }}
run: go build -v ./...

- name: Test
env:
CGO_LDFLAGS_ALLOW: '-w'
run: go test -v --ldflags '-L./lib' ./...
APPKEY: ${{ secrets.APPKEY }}
SECRET: ${{ secrets.APP_SECRET }}
run: go test -v ./...
9 changes: 7 additions & 2 deletions .github/workflows/goformatter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ jobs:
build:
name: Golang Formatter
runs-on: ubuntu-latest
env:
GOPATH: ${{ github.workspace }}
package: src/github.com/${{ github.repository }}
defaults:
run:
working-directory: ${{ env.GOPATH }}/${{ env.package }}
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Golang Formatter
uses: sladyn98/auto-go-format@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

23 changes: 11 additions & 12 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,26 @@ on:
jobs:
goreleaser:
runs-on: ubuntu-latest
env:
cache: ${{ github.workspace }}/go.sum
steps:
-
name: Checkout
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.16
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
go-version: '1.18'
cache-dependency-path: ${{ env.cache }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --rm-dist
args: release --clean
env:
CGO_LDFLAGS_ALLOW: '-w'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
36 changes: 25 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
*.dylib

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

# Test binary, built with `go test -c`
*.test
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
_testmain.go

# Dependency directories (remove the comment below to include it)
# vendor/
*.exe
*.test
*.prof

.DS_Store
*/.DS_Store
test
config.toml
.vim
.idea
15 changes: 8 additions & 7 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an example .goreleaser.yml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
project_name: "WeWorkFinanceSDK"
project_name: "oceanengine"
before:
hooks:
# You may remove this if you don't use go modules.
Expand All @@ -10,12 +10,13 @@ before:
builds:
- skip: true
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
- id: oceanengine
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
10 changes: 5 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package wxworkfinancesdk

// #cgo LDFLAGS: -w -L${SRCDIR}/lib -lWeWorkFinanceSdk_C
// #cgo LDFLAGS: -L${SRCDIR}/lib -lWeWorkFinanceSdk_C
// #cgo CFLAGS: -Wall
// #cgo CFLAGS: -I ${SRCDIR}/lib/
// #include <stdlib.h>
Expand All @@ -14,7 +14,7 @@ import (

// Client Client对象
type Client struct {
ptr C.WeWorkFinanceSdk_t
ptr *C.WeWorkFinanceSdk_t
}

// NewClient 初始化函数
Expand Down Expand Up @@ -91,7 +91,7 @@ func (c *Client) DecryptData(encryptKey string, encryptMsg string) (Message, err
C.FreeSlice(msgSlice)
}()

retC := C.DecryptData(encryptKey, encryptMsg, msgSlice)
retC := C.DecryptData(encryptKeyC, encryptMsgC, msgSlice)
ret := int(retC)
if ret != 0 {
return nil, NewSDKErr(ret)
Expand Down Expand Up @@ -195,7 +195,7 @@ func (c *Client) GetMediaData(indexBuf string, sdkFileId string, proxy string, p
}
return &MediaData{
OutIndexBuf: C.GoString(C.GetOutIndexBuf(mediaDataC)),
Data: C.GoBytes(C.GetData(mediaDataC), int(C.GetDataLen(mediaDataC))),
Data: C.GoBytes(unsafe.Pointer(C.GetData(mediaDataC)), C.GetDataLen(mediaDataC)),
IsFinish: int(C.IsMediaDataFinish(mediaDataC)) == 1,
}, nil
}
Expand All @@ -219,5 +219,5 @@ func (c *Client) DownloadMedia(w io.Writer, sdkField string, proxy string, passw

// GetContentFromSlice 转换C.struct_Slice_t为go bytes
func (c Client) GetContentFromSlice(slice *C.struct_Slice_t) []byte {
return C.GoBytes(C.GetContentFromSlice(slice), int(C.GetSliceLen(slice)))
return C.GoBytes(unsafe.Pointer(C.GetContentFromSlice(slice)), C.GetSliceLen(slice))
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/bububa/WeWorkFinanceSDK

go 1.16
go 1.18

0 comments on commit 2a30ca3

Please sign in to comment.