go中导入语句中的占位符

发布于 2025-01-10 15:29:25 字数 454 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡紫姑娘! 2025-01-17 15:29:25

将其添加到 go.mod 文件中:

replace github.com/Dir1/Dir2/v101/ServiceName => github.com/Dir1/Dir2/v102/ServiceName

现在,您可以在任何地方继续使用 github.com/Dir1/Dir2/v101/ServiceName,并更新此 replace<每次版本需要更新时 /code> 指令。例如,如果下一个版本是 v103,请更新以下内容:

replace github.com/Dir1/Dir2/v101/ServiceName => github.com/Dir1/Dir2/v103/ServiceName

Add this in the go.mod file:

replace github.com/Dir1/Dir2/v101/ServiceName => github.com/Dir1/Dir2/v102/ServiceName

Now, you can keep using github.com/Dir1/Dir2/v101/ServiceName everywhere, and update this replace directive every time the version needs to be updated. For example, if the next version is v103, update this:

replace github.com/Dir1/Dir2/v101/ServiceName => github.com/Dir1/Dir2/v103/ServiceName
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文