构建与部署插件
构建
This tutorial assumes you want to build plugins for gotify/server. If you wish to build for a different version,replace v2.0.0 with your desired version number.
gotify/plugin-template Makefile 已经包含了构建插件所需完成的大部分任务,你可以自由地将该 Makefile 复制到你自己的插件项目中使用。
cd 进入插件源代码目录:
$ cd /path/to/plugin/source
$ ls
main.go go.mod go.sum
(可选)确保没有依赖冲突:
从 gotify/server 获取 go.mod 文件。
Github.com/gotify/server/blob/v2.0.0/go.mod
并运行以下命令:
$ go get -u github.com/gotify/plugin-api/cmd/gomod-cap
$ go run github.com/gotify/plugin-api/cmd/gomod-cap \
-from /path/to/gotify/server/source/go.mod -to /path/to/plugin/source/go.mod
$ go mod tidy
使用 Docker(推荐)
该
Gotify/build Docker 镜像
用于构建 gotify/server。建议
建议为插件使用相同的构建环境以确保兼容性。
如果你不想使用
Gotify/plugin-template 的 Makefile
那么你可以像这样构建你的插件:
在一个名为GO_VERSION.
Github.com/gotify/server/blob/v2.0.0/GO_VERSION
在这种情况下1.12.0.
运行 Docker 镜像。gotify/build 的 Docker 镜像标签遵循以下格式:
意味着可选)
linux amd64
$ docker run --rm -v "$PWD/.:/proj" -w /proj gotify/build:1.12.0-linux-amd64 \
go build -a -installsuffix cgo -ldflags "-w -s" -buildmode=plugin -o yourplugin-amd64.so /proj
linux arm-7
$ docker run --rm -v "$PWD/.:/proj" -w /proj gotify/build:1.12.0-linux-arm-7 \
go build -a -installsuffix cgo -ldflags "-w -s" -buildmode=plugin -o yourplugin-arm-7.so /proj
Linux ARM64
$ docker run --rm -v "$PWD/.:/proj" -w /proj gotify/build:1.12.0-linux-arm64 \
go build -a -installsuffix cgo -ldflags "-w -s" -buildmode=plugin -o yourplugin-arm64.so /projlinux 386
$ docker run --rm -v "$PWD/.:/proj" -w /proj gotify/build:1.12.0-linux-386 \
go build -a -installsuffix cgo -ldflags "-w -s" -buildmode=plugin -o yourplugin-386.so /projWithout Docker (not recommended)
Plugins built without the gotify/server build environment, will probably not work with the built binaries from
gotify/server Releases.
Install the Go version that was used for building gotify/server. The version can be found in the gotify/server repository
in a file called GO_VERSION. github.com/gotify/server/blob/v2.0.0/GO_VERSION.
If you are in GOPATH, enable go modules explicitly:
$ export GO111MODULE=onBuild the plugin:
$ go build -o /path/to/gotify/plugin/dir/myplugin.so -buildmode=pluginDeploying
Gotify loads plugin from the pluginsdir directory in the configuration. All files in that directory are loaded as plugins.
Copy built shared object to the gotify plugin directory:
$ cp myplugin.so "${GOTIFY_PLUGINSDIR}/myplugin.so"Start gotify:
$ gotifyTroubleshooting
cannot load plugin (<plugin_filename>): package (<plugin_package>) was built with another version of package(<conflicting_package>)
- If the conflicting package is in the standard library (does not start with a hostname):
- Check if your plugin is built with go modules enabled ( try
GO111MODULE=on) - If you are using the official release, your plugin should be built with the same version of go toolchain as the build environment (
go version)
- Check if your plugin is built with go modules enabled ( try
- If the conflicting package is a 3rd party dependency (starts with a hostname, eg:
github.com/...):- Check if your project
go.modis out of date (go mod tidy) - Your plugin might have a common dependency with gotify but with a different version, modify that dependency version manually in
go.modor use gomod-cap.
- Check if your project
- If you still cannot resolve the dependency issue, try building gotify from source.
最后编辑:Jeebiz 更新时间:2025-12-04 11:29