如何使用`go install`命令创建git仓库并撤销错误发布的pkg.go.dev包?

huangapple go评论80阅读模式
英文:

How make git repo install with `go install` command and retract mistakenly published pkg.go.dev package?

问题

我有一个小的package,根目录下有 main.go 和 go.mod 文件,src/* 目录下有一些文件,src 目录中的文件都包含了 package name

以下是 main.go 的内容:

package main

import (
	package_name "github.com/user/package/src"
)

func main() {
	package_name.Run()
}

以下是 go.mod 的内容:

module github.com/user/package

go 1.20

我试图模仿 https://github.com/junegunn/fzf 的结构。但是在我的情况下,每当我尝试运行 go install github.com/user/package@latest 时,我都会收到一个错误消息 package github.com/user/package is not a main package,而 fzf 则没有出现这个问题,请问你能解释一下为什么吗?

英文:

I have a small package which has main.go and go.mod in root directory and couple of files in src/*, files inside src contain package name on all files:

Here is the contents of main.go:

package main

import (
	package_name "github.com/user/package/src"
)

func main() {
	package_name.Run()
}

Here is go.mod:

module github.com/user/package

go 1.20

I am trying to mimic structure of https://github.com/junegunn/fzf. But in my case whenever I try to do go install github.com/user/package@latest I get an error package github.com/user/package is not a main package same does not happen with fzf can you please explain my why?

答案1

得分: 1

根据 https://pkg.go.dev/github.com/asolopovas/dsync?tab=versions,你之前发布过 v1.0.0 版本。使用 -x 选项运行 go install 命令可以确认:

$ go clean -modcache
$ go install -x github.com/asolopovas/dsync@latest
# get https://proxy.golang.org/github.com/@v/list
# get https://proxy.golang.org/github.com/asolopovas/@v/list
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/list
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/list: 200 OK (1.202s)
# get https://proxy.golang.org/github.com/@v/list: 404 Not Found (1.202s)
# get https://proxy.golang.org/github.com/asolopovas/@v/list: 404 Not Found (1.202s)
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/v1.0.0.info
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/v1.0.0.info: 200 OK (0.293s)
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/v1.0.0.mod
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/v1.0.0.mod: 200 OK (0.617s)
# get https://proxy.golang.org/sumdb/sum.golang.org/supported
# get https://proxy.golang.org/sumdb/sum.golang.org/supported: 404 Not Found (0.304s)
# <output truncated>
go: downloading github.com/asolopovas/dsync v1.0.0
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/v1.0.0.zip
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/v1.0.0.zip: 200 OK (0.324s)
package github.com/asolopovas/dsync is not a main package

下载 https://proxy.golang.org/github.com/asolopovas/dsync/@v/v1.0.0.zip 并检查其内容。确实,v1.0.0 版本的 github.com/asolopovas/dsync 包不是一个主要包。

现在你已经更新了 master 分支,将其转换为一个主要包,给它打上一个新的版本标签(例如 v1.1.0),然后再次尝试。希望 go install github.com/asolopovas/dsync@latest 现在能够正常工作。

英文:

According to https://pkg.go.dev/github.com/asolopovas/dsync?tab=versions, you have published v1.0.0 before. Run go install with the -x option confirms that:

$ go clean -modcache
$ go install -x github.com/asolopovas/dsync@latest
# get https://proxy.golang.org/github.com/@v/list
# get https://proxy.golang.org/github.com/asolopovas/@v/list
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/list
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/list: 200 OK (1.202s)
# get https://proxy.golang.org/github.com/@v/list: 404 Not Found (1.202s)
# get https://proxy.golang.org/github.com/asolopovas/@v/list: 404 Not Found (1.202s)
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/v1.0.0.info
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/v1.0.0.info: 200 OK (0.293s)
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/v1.0.0.mod
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/v1.0.0.mod: 200 OK (0.617s)
# get https://proxy.golang.org/sumdb/sum.golang.org/supported
# get https://proxy.golang.org/sumdb/sum.golang.org/supported: 404 Not Found (0.304s)
# <output truncated>
go: downloading github.com/asolopovas/dsync v1.0.0
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/v1.0.0.zip
# get https://proxy.golang.org/github.com/asolopovas/dsync/@v/v1.0.0.zip: 200 OK (0.324s)
package github.com/asolopovas/dsync is not a main package

Download https://proxy.golang.org/github.com/asolopovas/dsync/@v/v1.0.0.zip and check its content. Indeed the package github.com/asolopovas/dsync at v1.0.0 is not a main package.

Now you have updated the master branch to turn it into a main package, tag a new version (such as v1.1.0) and try again. Hopefully go install github.com/asolopovas/dsync@latest should work now.

答案2

得分: 0

我通过阅读文档,在我的go.mod文件中添加了撤销属性,并创建了一个新的标签v1.0.1(像v1.1这样的标签不起作用,所以我选择了v1.0.1的格式),正如Zeke Lu建议的那样。然后我访问了https://pkg.go.dev/github.com/username/package@v1.0.1,并点击请求,过夜之间我就有了一个可以使用go install命令的新版本的包。

go.mod

module github.com/asolopovas/dsync

go 1.20

retract (
    v1.0.0 // 无意中发布的版本。
    v0.1.0 // 无意中发布的版本。
)
英文:

I fixed my problem by reading docs, adding retraction attribute to my go.mod file, and creating new tag v1.0.1 (tags like v1.1 did not work, so i had to choose v1.0.1 format) as was suggested by Zeke Lu, then I visited https://pkg.go.dev/github.com/username/package@v1.0.1 and clicked request and overnight I have a new version of the package which works with go install command.

go.mod

module github.com/asolopovas/dsync

go 1.20

retract (
    v1.0.0 // Published accidentally.
    v0.1.0 // Published accidentally.
)

huangapple
  • 本文由 发表于 2023年6月10日 22:18:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76446618.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定