Golang won't import remote packages without a top level domain
I was trying to pull a Go package from a private Github enterprise server that had no top level domain (TLD) in it's hostname. Just git. Internally it resolved to git.company.net but was accessed just through git.
My issues started then the go tool tried to pull a dependency from the import path "git/JesseMichael/project/package" but failed with the error:
go/src/cmd/go/internal/get/vcs.go#L766-L769
Go does not allow you to have a remote import path for a server without a . in the hostname. But changing the import path to include the full hostname doesn't fix the problem. When the import path is "git.company.net/JesseMichael/project/package" I would get the error:
Why's that? Well as far as I can tell it has to do with the response that the Github server is returning to the request, git.company.net/JesseMichael/project?go-get=1
Reading Golang's documentation on remote import paths reveals that, at this point, the go tool doesn't know what version control system the remote server is. So it tests the server with the ?go-get=1 parameter, looking for the "go-import" meta tag.
Unfortunately for me, the Github server I'm using is returning path without the full hostname, just git/. That "go-import" meta tag fails verification and fails to pull the dependency.
All hope is not lost, though. There is a workaround. Not one that I particularly like, but it will do. You can the go tool what version control system an import path is by adding .git to the end of the repo in the import path: "git.company.net/JesseMichael/project.git/package" When using Go modules, you must also add the ".git" suffix to the module.
go/src/cmd/go/internal/get/vcs.go#L766-L769
Go does not allow you to have a remote import path for a server without a . in the hostname. But changing the import path to include the full hostname doesn't fix the problem. When the import path is "git.company.net/JesseMichael/project/package" I would get the error:
Why's that? Well as far as I can tell it has to do with the response that the Github server is returning to the request, git.company.net/JesseMichael/project?go-get=1
Reading Golang's documentation on remote import paths reveals that, at this point, the go tool doesn't know what version control system the remote server is. So it tests the server with the ?go-get=1 parameter, looking for the "go-import" meta tag.
Unfortunately for me, the Github server I'm using is returning path without the full hostname, just git/. That "go-import" meta tag fails verification and fails to pull the dependency.
All hope is not lost, though. There is a workaround. Not one that I particularly like, but it will do. You can the go tool what version control system an import path is by adding .git to the end of the repo in the import path: "git.company.net/JesseMichael/project.git/package" When using Go modules, you must also add the ".git" suffix to the module.
Comments
Post a Comment