Incorrect/confusing versioning of Go package located in non-root folder of git

  Kiến thức lập trình

I have a package at https://github.com/and3rson/fastmsg, it’s located in a go subdir since it’s a multi-language monorepo, thus I cannot keep the Go package at repo root.

Latest commit is tagged as v1.0.1, however:

  • Version at pkg.go.dev is shown as v0.0.0-xxx-yyy
  • Running go get github.com/and3rson/fastmsg/go@latest also fetches v0.0.0-xxx-yyy with some confusing output:
    # Why is and3rson/fastmsg fetched if the actual package is and3rson/fastmsg/go?
    go: downloading github.com/and3rson/fastmsg v1.0.1
    go: downloading github.com/and3rson/fastmsg/go v0.0.0-20240819225607-785e9a27b194
    go: added github.com/and3rson/fastmsg/go v0.0.0-20240819225607-785e9a27b194
    
  • Running go get github.com/and3rson/fastmsg (excluding /go suffix) fetches correct v1.0.1, however the package is not usable since the real package is inside go subdir.

I’m not sure whether it’s a bug or my (somehow) incorrect usage of the Go packaging system, but the observed behavior seems very unintuitive to me.

I also could not find any discussions describing this issue or documenting the correct usage of packages located in subdirs.

Expected behavior

I’m expecting a package that’s located in a subdir to behave the same way as a top-level package.

Basically, I’m expected to see the following:

$ go get github.com/and3rson/fastmsg/go
go: downloading github.com/and3rson/fastmsg/go v1.0.1
go: added github.com/and3rson/fastmsg/go v1.0.1

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT