gpt4 book ai didi

go - 如何使用备用 go.mod 文件进行本地开发?

转载 作者:行者123 更新时间:2023-12-04 14:05:14 27 4
gpt4 key购买 nike

目前我正在开发一个使用无服务器框架和 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 (andpossibly write) an alternate file instead of go.mod in the module rootdirectory. The file’s name must end with .mod. A file named go.modmust 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 flagby 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com