On Mon, Oct 25, 2021 at 5:01 PM Richard W.M. Jones <rjones@redhat.com> wrote:
[Adding Matthew]
On Mon, Oct 25, 2021 at 04:45:03PM +0300, Nir Soffer wrote:
I'm playing with libnbd go module, planning to use it in a new command[1]
The biggest obstacle for me is that the module is not published in a way that Go developers expect.
The module is listed in: https://pkg.go.dev/github.com/libguestfs/libnbd/golang
But the module actually lives in: https://github.com/libguestfs/libnbd/tree/master/golang/src/libguestfs.org/l...
So the pkg.go.dev page is broken, .e.g no there is no documation or license, and the suggested import is wrong.
The module name is "libguestfs.org/libnbd". But if you try to use it, for example in the (improved) example from libnbd-golang.pod:
$ cat test.go package main
import "fmt" import "libguestfs.org/libnbd"
func main() { h, err := libnbd.Create() if err != nil { panic(err) } defer h.Close() uri := "nbd://localhost" err = h.ConnectUri(uri) if err != nil { panic(err) } size, err := h.GetSize() if err != nil { panic(err) } fmt.Printf("size of %s = %d\n", uri, size) }
$ go mod init example/test go: creating new go.mod: module example/test go: to add module requirements and sums: go mod tidy
$ go mod tidy go: finding module for package libguestfs.org/libnbd example/test imports libguestfs.org/libnbd: cannot find module providing package libguestfs.org/libnbd: unrecognized import path "libguestfs.org/libnbd": reading https://libguestfs.org/libnbd?go-get=1: 404 Not Found
That website is entirely static so if it involves fetching stuff from there it's probably not going to work.
So the import path should be: gitlab.com/libnbd/golang/src/libguestfs.org/libnbd Since gitlab (or github) already supports go tools. ...
$ go mod edit -replace libguestfs.org/libnbd=../../src/libnbd/golang/src/libguestfs.org/libnbd $ go mod tidy go: found libguestfs.org/libnbd in libguestfs.org/libnbd v0.0.0-00010101000000-000000000000
$ cat go.mod module example/test
go 1.16
replace libguestfs.org/libnbd => ../../src/libnbd/golang/src/libguestfs.org/libnbd
require libguestfs.org/libnbd v0.0.0-00010101000000-000000000000
But the version is wrong - it should be v1.10.0. I think the issue is missing tag: https://golang.org/ref/mod#vcs-version
If a module is defined in a subdirectory within the repository, that is, the module subdirectory portion of the module path is not empty, then each tag name must be prefixed with the module subdirectory, followed by a slash. For example, the module golang.org/x/tools/gopls is defined in the gopls subdirectory of the repository with root path golang.org/x/tools. The version v0.4.0 of that module must have the tag named gopls/v0.4.0 in that repository.
So the linbd project needs a tag like: golang/src/libguestfs.org/libnbd/v1.10.0
I'm not sure I understand what this all means. Is that the literal name of the git tag (ie. git tag golang/src/libguestfs.org/libnbd/v1.10.0 )?
Yes, this is how I understand the docs. I did not try it yet. Nir