教程集 www.jiaochengji.com
教程集 >  Golang编程  >  golang教程  >  正文 golang go mod_go mod文件中的语义版本标记

golang go mod_go mod文件中的语义版本标记

发布时间:2023-03-18   编辑:jiaochengji.com
教程集为您提供golang go mod,go mod文件中的语义版本标记等资源,欢迎您收藏本站,我们将为您提供最新的golang go mod,go mod文件中的语义版本标记资源

golang go mod

Understanding the semantic version tags of the dependencies in the go.mod file in GoLang.

ünderstanding在依赖的语义版本标签 go.mod 在GoLang文件。

Before we begin, let’s review a quick description of GoLang and Go Modules:

在开始之前,让我们回顾一下GoLang和Go模块的快速描述:

Go is a statically typed, compiled & open source programming language backed by Google.Go 1.11 and 1.12 include preliminary support for modules, Go’s new dependency management system that makes dependency version information explicit and easier to manage…Starting in Go 1.13, module mode will be the default for all development.

Go是一种由Google支持的静态类型化,已编译和开放源代码的编程语言。Go1.11和1.12包括对模块的初步支持 ,Go的新依赖管理系统使依赖版本信息明确且易于管理……从Go 1.13开始,模块模式将是所有开发的默认设置。

那么,go.mod文件是什么? (So, what is the go.mod file?)

The go.mod file is the key to dependency resolution in the Go modules or packages. And in terms of blog.golang.org:

go.mod文件是Go模块或软件包中依赖关系解析的关键。 并且就blog.golang.org而言 :

The go.mod file defines the module’s module path, which is also the import path used for the root directory, and its dependency requirements, which are the other modules needed for a successful build. Each dependency requirement is written as a module path and a specific semantic version.

go.mod文件定义模块的模块路径(这也是用于根目录的导入路径)及其依赖关系要求,它们是成功构建所需的其他模块。 每个依赖性要求都写为模块路径和特定的语义版本 。

module github.com/Shivam010/scaling-cggo 1.14require github.com/Shivam010/crispy-giggle v0.0.0-20200716183311-8684572763dc

A module version is defined by a tree of source files, with a go.mod file in its root.

模块版本由源文件树定义,其根目录中带有go.mod文件。

So, the go.mod file defines our module requirements for a successful build, including all the dependencies with there corresponding versions, here stated as the specific semantic versions.

因此, go.mod文件定义了成功构建所需的模块要求,其中包括具有相应版本的所有依赖项,此处称为特定语义版本

These specific semantic versions are called Pseudo versions, which are used as the standard form for describing module versions in go.mod file, in a more visualised and comparable form than the typical representations like the project’s commit hash or only the release tags.

这些特定的语义版本称为Pseudo版本 ,它们用作go.mod文件中描述模块版本的标准形式,其形式比项目提交哈希或仅发布标记等典型表示形式更具可视性和可比性。

Each and every pseudo version contains three parts. As in the above example go.mod file, we have v0.0.0-20200716183311-8684572763dc for github.com/Shivam010/crispy-giggle project where:

每个伪版本都包含三个部分。 如上述示例go.mod文件中所示,对于github.com/Shivam010/crispy-giggle项目,我们具有v0.0.0-20200716183311-8684572763dc ,其中:

  1. v0.0.0 is the Release Version of the package (v0.0.0 is the default release version when no tags are defined)

    v0.0.0是程序包的发行版本 ( v0.0.0是未定义标签时的默认发行版本)

  2. 20200716183311 is the Time of Commit of the package in UTC: July 16 2020 18:33:11 UTC

    20200716183311是UTC 提交软件包的时间: July 16 2020 18:33:11 UTC

  3. 8684572763dc are the first 12 characters from the commit hash of the package: 8684572763dc96b1d86f174d1303fd7e8796fa7d

    8684572763dc是程序包的提交哈希中的前12个字符8684572763dc96b1d86f174d1303fd7e8796fa7d

These Pseudo versions are the best way of describing module versions. The time portion can easily be used to identify and compare the date and time of the last update. The 12 characters commit hash to identify the commit in the project history. And finally, the release tag prefix helps the recent tagged version in the repository. All three together make a perfect identifier for any project.

这些伪版本是描述模块版本的最佳方法。 时间部分可以轻松地用于识别和比较上次更新的日期和时间。 这12个字符的提交哈希标识了项目历史记录中的提交。 最后,发行标签前缀有助于存储库中最近标记的版本。 这三者共同构成了任何项目的完美标识符。

Note: Though the pseudo versions can be easily created for any project using their git history, one should never type them by hand. Also, there is no need of it.

注意 :尽管可以使用其git历史记录轻松地为任何项目创建伪版本,但切勿手动键入它们。 同样,也不需要它。

All Go tools like go mod, go build are intelligently equipped with the functionality of generating these pseudo-versions, all we have to provide is one of the following:

所有Go工具(例如go modgo build都智能地配备了生成这些伪版本的功能,我们仅需提供以下功能之一:

  1. Any commit hash of the project,

    项目的任何提交哈希,

  2. Or the corresponding branch name of the project,

    或项目的相应分支名称,

  3. Or the complete release tag vX.Y.Z

    或完整的发行标签vX.YZ

  4. Or the version comparison, e.g. >vX.Y.Z, <=vX.Y.Z

    或版本比较, eg >vX.YZ, <=vX.YZ

  5. Or the latest tag, (which matches the latest available tagged version),

    latest标签(与最新的可用标签版本匹配),

  6. Or the upgrade tag, (it’s like latest but also, include pre-releases),

    upgrade标签(既是最新版本,也包括预发布版本),

  7. Or the patch tag, (which matches the latest patched version tag available),

    patch标签(与可用的最新补丁版本标签匹配),

Hence, there is no need to type the Pseudo-versions of the package by hand. Go tools will accept one of the above 7 values for the project and translate it into a pseudo-version (or a tagged version if available) automatically. This conversion is an example of a module query in Go toolings. For better understanding follow the references provided in the end.

因此,无需手动键入程序包的伪版本。 Go工具将接受该项目的上述7个值之一,并将其​​自动转换为伪版本(或标记版本)(如果可用)。 此转换是Go工具中模块查询的示例。 为了更好地理解,请遵循最后提供的参考。

结论 (Conclusion)

go.mod file uses Pseudo versions to represent the module's dependencies using the commit timestamp, release version, and the commit hash, making the representation completely unique. Also, go toolings can automatically convert the common version representations like release tags, branch names, commit hash to Pseudo versions, so there’s no need to write or generate them manually.

go.mod文件使用伪版本通过提交时间戳,发行版本和提交哈希表来表示模块的依赖关系,从而使表示形式完全唯一。 另外,go工具可以自动转换常见的版本表示形式,例如发行标签,分支名称,将哈希提交到Pseudo版本,因此无需手动编写或生成它们。

And with the release of Go 1.14, the module support in the Go command is ready for production use and is highly recommended by the Go team. Hence, I suggest a more thorough & deep understanding of Go modules is a must for every Go developer.

随着Go 1.14的发布,Go命令中的模块支持已准备就绪,可以投入生产使用 ,并受到Go团队的强烈建议 。 因此,我建议对每个Go开发人员都必须对Go模块有更透彻,更深入的了解。

Thank you for reading! Any pitfalls we should be aware of? Let us know.~ Sh

感谢您的阅读! 我们应该注意的任何陷阱? 让我们知道

翻译自: https://medium.com/swlh/semantic-version-tags-in-go-mod-file-f6ad903a972d

golang go mod

到此这篇关于“golang go mod_go mod文件中的语义版本标记”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!

您可能感兴趣的文章:

[关闭]
~ ~