目前我正在开发一个使用无服务器框架和 Go 的 API。
我正在使用 Serverless-offline 插件进行本地测试。
这个 API 依赖于其他一些存储库(我也维护),我使用 go.mod
导入它们。文件。
但是,我很难完善我的开发人员工作流程。
目前,如果我想在此 API 所依赖的存储库中进行更改,我必须更改项目 go.mod
包括 replace directives出于测试目的,但随后我不得不手动将其更改回以部署到生产环境。
基本上我正在寻找一种包含替换指令的方法,该指令仅在本地开发过程中应用 .其他人是如何解决这个问题的?
额外问题:有没有办法在 docker 中离线运行 Serverless?我发现在裸机上运行的无服务器离线导致不同开发人员环境之间的不一致。
最佳答案
您可以运行 go
带有备用命令 go.mod
带有 -modfile
的文件选项:
来自 Build commands :
The
-modfile=file.mod
flag instructs the go command to read (and possibly write) an alternate file instead ofgo.mod
in the module root directory. The file’s name must end with.mod
. A file namedgo.mod
must still be present in order to determine the module root directory, but it is not accessed. When-modfile
is specified, an alternatego.sum
file is also used: its path is derived from the-modfile
flag by trimming the .mod extension and appending .sum.
创建一个
local.go.mod
包含必要的文件 replace
用于开发和构建的指令,例如:go build -modfile=local.go.mod ./...
关于go - 如何使用备用 go.mod 文件进行本地开发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68764637/