Skip to content

Commit 2a30ca3

Browse files
committed
fix(client): cgo problem
1 parent 2d5ca8e commit 2a30ca3

File tree

7 files changed

+86
-47
lines changed

7 files changed

+86
-47
lines changed

.github/workflows/go.yml

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
11
name: Go
2-
on: [push, pull_request]
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
pull_request:
7+
branches: [ master, main ]
8+
39
jobs:
410

511
build:
612
runs-on: ubuntu-latest
13+
env:
14+
GOPATH: ${{ github.workspace }}
15+
package: src/github.com/${{ github.repository }}
16+
defaults:
17+
run:
18+
working-directory: ${{ env.GOPATH }}/${{ env.package }}
719
steps:
8-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v3
21+
with:
22+
path: ${{ env.GOPATH }}/${{ env.package }}
923

1024
- name: Set up Go
11-
uses: actions/setup-go@v2
25+
uses: actions/setup-go@v4
1226
with:
13-
go-version: 1.16
27+
go-version: '1.18'
28+
cache-dependency-path: |
29+
${{ env.GOPATH }}/${{ env.package }}/go.mod
30+
${{ env.GOPATH }}/${{ env.package }}/go.sum
31+
32+
- name: Dependencies
33+
run: go mod download
1434

1535
- name: Build
16-
env:
17-
CGO_LDFLAGS_ALLOW: '-w'
18-
run: go build -v --ldflags '-L./lib' ./...
36+
working-directory: ${{ env.GOPATH }}/${{ env.package }}
37+
run: go build -v ./...
1938

2039
- name: Test
2140
env:
22-
CGO_LDFLAGS_ALLOW: '-w'
23-
run: go test -v --ldflags '-L./lib' ./...
41+
APPKEY: ${{ secrets.APPKEY }}
42+
SECRET: ${{ secrets.APP_SECRET }}
43+
run: go test -v ./...

.github/workflows/goformatter.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ jobs:
44
build:
55
name: Golang Formatter
66
runs-on: ubuntu-latest
7+
env:
8+
GOPATH: ${{ github.workspace }}
9+
package: src/github.com/${{ github.repository }}
10+
defaults:
11+
run:
12+
working-directory: ${{ env.GOPATH }}/${{ env.package }}
713
steps:
8-
- uses: actions/checkout@master
14+
- uses: actions/checkout@v3
915
with:
1016
fetch-depth: 0
1117
- name: Golang Formatter
1218
uses: sladyn98/auto-go-format@master
1319
env:
1420
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15-

.github/workflows/goreleaser.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,26 @@ on:
88
jobs:
99
goreleaser:
1010
runs-on: ubuntu-latest
11+
env:
12+
cache: ${{ github.workspace }}/go.sum
1113
steps:
12-
-
13-
name: Checkout
14-
uses: actions/checkout@v2
14+
- name: Checkout
15+
uses: actions/checkout@v3
1516
with:
1617
fetch-depth: 0
17-
-
18-
name: Set up Go
19-
uses: actions/setup-go@v2
18+
- name: Set up Go
19+
uses: actions/setup-go@v4
2020
with:
21-
go-version: 1.16
22-
-
23-
name: Run GoReleaser
24-
uses: goreleaser/goreleaser-action@v2
21+
go-version: '1.18'
22+
cache-dependency-path: ${{ env.cache }}
23+
- name: Run GoReleaser
24+
uses: goreleaser/goreleaser-action@v4
2525
with:
2626
# either 'goreleaser' (default) or 'goreleaser-pro'
2727
distribution: goreleaser
2828
version: latest
29-
args: release --rm-dist
29+
args: release --clean
3030
env:
31-
CGO_LDFLAGS_ALLOW: '-w'
3231
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3332
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
3433
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}

.gitignore

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
1-
# Binaries for programs and plugins
2-
*.exe
3-
*.exe~
4-
*.dll
1+
# Compiled Object files, Static and Dynamic libs (Shared Objects)
2+
*.o
3+
*.a
54
*.so
6-
*.dylib
5+
6+
# Folders
7+
_obj
8+
_test
9+
10+
# Architecture specific extensions/prefixes
11+
*.[568vq]
12+
[568vq].out
713

8-
# Test binary, built with `go test -c`
9-
*.test
14+
*.cgo1.go
15+
*.cgo2.c
16+
_cgo_defun.c
17+
_cgo_gotypes.go
18+
_cgo_export.*
1019

11-
# Output of the go coverage tool, specifically when used with LiteIDE
12-
*.out
20+
_testmain.go
1321

14-
# Dependency directories (remove the comment below to include it)
15-
# vendor/
22+
*.exe
23+
*.test
24+
*.prof
1625

1726
.DS_Store
27+
*/.DS_Store
28+
test
29+
config.toml
30+
.vim
31+
.idea

.goreleaser.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This is an example .goreleaser.yml file with some sane defaults.
22
# Make sure to check the documentation at http://goreleaser.com
3-
project_name: "WeWorkFinanceSDK"
3+
project_name: "oceanengine"
44
before:
55
hooks:
66
# You may remove this if you don't use go modules.
@@ -10,12 +10,13 @@ before:
1010
builds:
1111
- skip: true
1212
archives:
13-
- replacements:
14-
darwin: Darwin
15-
linux: Linux
16-
windows: Windows
17-
386: i386
18-
amd64: x86_64
13+
- id: oceanengine
14+
name_template: >-
15+
{{ .ProjectName }}_
16+
{{- title .Os }}_
17+
{{- if eq .Arch "amd64" }}x86_64
18+
{{- else if eq .Arch "386" }}i386
19+
{{- else }}{{ .Arch }}{{ end }}
1920
checksum:
2021
name_template: 'checksums.txt'
2122
snapshot:

client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package wxworkfinancesdk
22

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

1515
// Client Client对象
1616
type Client struct {
17-
ptr C.WeWorkFinanceSdk_t
17+
ptr *C.WeWorkFinanceSdk_t
1818
}
1919

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

94-
retC := C.DecryptData(encryptKey, encryptMsg, msgSlice)
94+
retC := C.DecryptData(encryptKeyC, encryptMsgC, msgSlice)
9595
ret := int(retC)
9696
if ret != 0 {
9797
return nil, NewSDKErr(ret)
@@ -195,7 +195,7 @@ func (c *Client) GetMediaData(indexBuf string, sdkFileId string, proxy string, p
195195
}
196196
return &MediaData{
197197
OutIndexBuf: C.GoString(C.GetOutIndexBuf(mediaDataC)),
198-
Data: C.GoBytes(C.GetData(mediaDataC), int(C.GetDataLen(mediaDataC))),
198+
Data: C.GoBytes(unsafe.Pointer(C.GetData(mediaDataC)), C.GetDataLen(mediaDataC)),
199199
IsFinish: int(C.IsMediaDataFinish(mediaDataC)) == 1,
200200
}, nil
201201
}
@@ -219,5 +219,5 @@ func (c *Client) DownloadMedia(w io.Writer, sdkField string, proxy string, passw
219219

220220
// GetContentFromSlice 转换C.struct_Slice_t为go bytes
221221
func (c Client) GetContentFromSlice(slice *C.struct_Slice_t) []byte {
222-
return C.GoBytes(C.GetContentFromSlice(slice), int(C.GetSliceLen(slice)))
222+
return C.GoBytes(unsafe.Pointer(C.GetContentFromSlice(slice)), C.GetSliceLen(slice))
223223
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/bububa/WeWorkFinanceSDK
22

3-
go 1.16
3+
go 1.18

0 commit comments

Comments
 (0)