go中导入语句中的占位符
我正在使用 go 语言,我想了解我所面临的一种情况的替代方案。
我们在文件中有 import 语句,因为
import "github.com/Dir1/Dir2/v101/ServiceName"
我依赖于 SDK,它遵循这样的目录结构。它有 version_no 目录。
问题 - 每次更新 SDK 版本时,我们都必须用适当的版本替换导入语句。
目前在项目中是使用 sed 命令来实现的,由于我们有数千个文件,这是一个非常繁重的操作。 例如更改“github.com/Dir1/Dir2/v101/ServiceName”==> “github.com/Dir1/Dir2/v102/ServiceName”
SDK团队不会提供任何支持,因此我们必须找到解决此问题的好方法。
我需要您关于如何实现这一目标的建议。
I am using the go language and I want to understand the alternative to one scenario that I am facing.
we have import statements in the files as
import "github.com/Dir1/Dir2/v101/ServiceName"
I have a dependency on SDK which follows the directory structure like this. It has version_no directory.
Problem - Every-time the SDK version is updated we have to replace the import statement with appropriate version.
Currently in project it is achieved using the sed command which is very heavy operation as we have thousands of files.
Ex Changing "github.com/Dir1/Dir2/v101/ServiceName" ==> "github.com/Dir1/Dir2/v102/ServiceName"
SDK team will not provide any support so we have to find the good way to resolve this.
I need your suggestion about how this can be achieved.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其添加到
go.mod
文件中:现在,您可以在任何地方继续使用
github.com/Dir1/Dir2/v101/ServiceName
,并更新此replace<每次版本需要更新时 /code> 指令。例如,如果下一个版本是
v103
,请更新以下内容:Add this in the
go.mod
file:Now, you can keep using
github.com/Dir1/Dir2/v101/ServiceName
everywhere, and update thisreplace
directive every time the version needs to be updated. For example, if the next version isv103
, update this: