search
HomeBackend DevelopmentGolangCan a Go module be published in the same path as a previous non-module module?

Go 模块可以与之前的非模块模块发布在同一路径吗?

Go module is an important feature introduced in Go language version 1.11. It can help developers better manage and rely on third-party libraries in projects. For the previous projects developed in non-module mode, PHP editor Banana tells everyone that modules and non-module modules can be published in the same path. The advantage of this is that it can easily and gradually migrate existing projects to the module mode, while also maintaining the usability and stability of the project. However, it should be noted that when publishing modules and non-module modules under the same path, you need to follow some rules and conventions to ensure the normal operation of the project.

Question content

I have a small library that has been hosted in a non-module repository, but I now want to convert it to a go module.

I successfully executed:

go mod init
go mod tidy
The

go.mod and go.sum files are created without errors, and the library still passes the test.

The previous version was v2.0.0, so I increased the version to v3.0.0 and added /v3 to go. mod at the end of the module name. From what I've seen online, this is what is needed. My go.mod file looks like this:

module tssgit.reyrey.com/teschste/go-utils/v3

go 1.19

require (
    github.com/lib/pq v1.10.9
    golang.org/x/text v0.9.0
)

I then published the library to our internal git server and thought I was ready.

When I try to add the library to a new go module project, I receive the following message:

Installing: tssgit.reyrey.com/teschste/go-utils/v3
Installing dependency: tssgit.reyrey.com/teschste/go-utils/v3
go: module tssgit.reyrey.com/teschste/go-utils@upgrade found (v2.0.0+incompatible), but does not contain package tssgit.reyrey.com/teschste/go-utils/v3
Failed to add dependencies: exit status 1

I found that if I published v3.0.0 to a new path (tssgit.reyrey.com/teschste/go-utils2) I was able to successfully add it to my new project, even if I increase the main project version again.

Am I missing something that would allow me to continue publishing on the same path, or is this just something you can't do?

Any help would be greatly appreciated!

Solution

Yes, this is supported. The version subdirectory is optional.

I found a situation that causes the error you are seeing. This happens when the master branch is not updated (still points to tag v2.0.0) and the new tag v3.0.0 is not pushed to the server. Please double check to make sure the remote repository is updated.

If the remote repository has been updated but still not working properly, you can narrow down the problem like this:

  1. Run with the -x option go get:

    $ go get -x tssgit.reyrey.com/teschste/go-utils/v3
  2. cd Go to the directory shown in the output. The directory path is like this:

    /home/username/go/pkg/mod/cache/vcs/96f42aa32430149c99ad6625ceafc5b59e047b9e11d6a03f687d59845b53b2d5
  3. In this directory, run git ls-remote -q origin and check the output. The example below is when it doesn't work on my machine. You can see that head and v2.0.0 both point to the same commit id, and there is no v3.0.0.

    $ git ls-remote -q origin
    5ac4c172806e80461086ea9feb485cec0b6a27f0    HEAD
    5ac4c172806e80461086ea9feb485cec0b6a27f0    refs/heads/main
    bbdc583c0b83489db1a30fa6ca8559ffa295a74d    refs/heads/other-branch
    5ac4c172806e80461086ea9feb485cec0b6a27f0    refs/tags/v2.0.0

The above is the detailed content of Can a Go module be published in the same path as a previous non-module module?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:stackoverflow. If there is any infringement, please contact admin@php.cn delete
String Manipulation in Go: Mastering the 'strings' PackageString Manipulation in Go: Mastering the 'strings' PackageMay 14, 2025 am 12:19 AM

Mastering the strings package in Go language can improve text processing capabilities and development efficiency. 1) Use the Contains function to check substrings, 2) Use the Index function to find the substring position, 3) Join function efficiently splice string slices, 4) Replace function to replace substrings. Be careful to avoid common errors, such as not checking for empty strings and large string operation performance issues.

Go 'strings' package tips and tricksGo 'strings' package tips and tricksMay 14, 2025 am 12:18 AM

You should care about the strings package in Go because it simplifies string manipulation and makes the code clearer and more efficient. 1) Use strings.Join to efficiently splice strings; 2) Use strings.Fields to divide strings by blank characters; 3) Find substring positions through strings.Index and strings.LastIndex; 4) Use strings.ReplaceAll to replace strings; 5) Use strings.Builder to efficiently splice strings; 6) Always verify input to avoid unexpected results.

'strings' Package in Go: Your Go-To for String Operations'strings' Package in Go: Your Go-To for String OperationsMay 14, 2025 am 12:17 AM

ThestringspackageinGoisessentialforefficientstringmanipulation.1)Itofferssimpleyetpowerfulfunctionsfortaskslikecheckingsubstringsandjoiningstrings.2)IthandlesUnicodewell,withfunctionslikestrings.Fieldsforwhitespace-separatedvalues.3)Forperformance,st

Go bytes package vs strings package: Which should I use?Go bytes package vs strings package: Which should I use?May 14, 2025 am 12:12 AM

WhendecidingbetweenGo'sbytespackageandstringspackage,usebytes.Bufferforbinarydataandstrings.Builderforstringoperations.1)Usebytes.Bufferforworkingwithbyteslices,binarydata,appendingdifferentdatatypes,andwritingtoio.Writer.2)Usestrings.Builderforstrin

How to use the 'strings' package to manipulate strings in Go step by stepHow to use the 'strings' package to manipulate strings in Go step by stepMay 13, 2025 am 12:12 AM

Go's strings package provides a variety of string manipulation functions. 1) Use strings.Contains to check substrings. 2) Use strings.Split to split the string into substring slices. 3) Merge strings through strings.Join. 4) Use strings.TrimSpace or strings.Trim to remove blanks or specified characters at the beginning and end of a string. 5) Replace all specified substrings with strings.ReplaceAll. 6) Use strings.HasPrefix or strings.HasSuffix to check the prefix or suffix of the string.

Go strings package: how to improve my code?Go strings package: how to improve my code?May 13, 2025 am 12:10 AM

Using the Go language strings package can improve code quality. 1) Use strings.Join() to elegantly connect string arrays to avoid performance overhead. 2) Combine strings.Split() and strings.Contains() to process text and pay attention to case sensitivity issues. 3) Avoid abuse of strings.Replace() and consider using regular expressions for a large number of substitutions. 4) Use strings.Builder to improve the performance of frequently splicing strings.

What are the most useful functions in the GO bytes package?What are the most useful functions in the GO bytes package?May 13, 2025 am 12:09 AM

Go's bytes package provides a variety of practical functions to handle byte slicing. 1.bytes.Contains is used to check whether the byte slice contains a specific sequence. 2.bytes.Split is used to split byte slices into smallerpieces. 3.bytes.Join is used to concatenate multiple byte slices into one. 4.bytes.TrimSpace is used to remove the front and back blanks of byte slices. 5.bytes.Equal is used to compare whether two byte slices are equal. 6.bytes.Index is used to find the starting index of sub-slices in largerslices.

Mastering Binary Data Handling with Go's 'encoding/binary' Package: A Comprehensive GuideMastering Binary Data Handling with Go's 'encoding/binary' Package: A Comprehensive GuideMay 13, 2025 am 12:07 AM

Theencoding/binarypackageinGoisessentialbecauseitprovidesastandardizedwaytoreadandwritebinarydata,ensuringcross-platformcompatibilityandhandlingdifferentendianness.ItoffersfunctionslikeRead,Write,ReadUvarint,andWriteUvarintforprecisecontroloverbinary

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft