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

标签 go local serverless go-modules

目前我正在开发一个使用无服务器框架和 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 of go.mod in the module root directory. The file’s name must end with .mod. A file named go.mod must still be present in order to determine the module root directory, but it is not accessed. When -modfile is specified, an alternate go.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/

相关文章:

ajax - 使用 ajax 的网络抓取工具/爬虫

go - bufio.NewReader.ReadString() 中没有缓冲区大小限制?

ldap - 是否可以为 LDAP 用户设置本地组

perl - perl 脚本的无服务器执行?

amazon-web-services - 为什么 AWS Gateway 为从 S3 流式传输的图像设置了错误的内容长度?

Goroutine 执行几秒后停止

MongoDB 与 golang 错误 "no reachable servers"

docker - 标签: while pushing image to local registry在本地不存在图像

Javascript:从页面内的内容将数据下载到文件

go - 如何在 Golang Cloud 函数中重用数据库连接?