更新时间:2023-12-13 GMT+08:00
分享

Go插件编译约束

约束声明

Go语言对插件约束较多,如Go版本、第三方依赖版本、编译参数等,插件需要与性能测试服务执行器主程序严格一致,否则将出现包括但不限于Go插件编译约束表中描述的异常,请严格按照约定编译so文件。

表1 Go插件编译约束表

约束项

约束值

说明

arch

linux amd64

-

Go版本

1.19.6

执行go version查看版本。

  • 中版本不一致时产生如下异常:

    fatal error: runtime: no plugin module data

  • 小版本不一致时产生如下异常:

    plugin was built with a different version of package runtime

go.mod

github.com/go-resty/resty/v2 v2.7.0

github.com/shopspring/decimal v1.3.1

github.com/xuri/excelize/v2 v2.6.0

github.com/tidwall/gjson v1.14.4

github.com/valyala/fasthttp v1.43.0

go.uber.org/atomic v1.10.0

golang.org/x/net v0.8.0

golang.org/x/time v0.2.0

如果直接或者间接使用了第三方库,需要在go.mod文件中使用约束值提供的版本。

第三方版本不一致将产生如下异常:

plugin was built with a different version of package github.com/json-iterator/go

TrimPath

使用TrimPath

如果不使用将产生如下异常:

plugin was built with a different version of package internal/unsafeheader

使用linux命令strip移除符号及调试信息。

编译样例

go build -buildmode=plugin -trimpath -o random.so random.go
strip random.so
分享:

    相关文档

    相关产品