2

My module is gitlab.com/getsote/utilities/slogger My repository is gitlab.com/getsote/utilities/slogger.git When I run go get gitlab.com/getsote/utilities/slogger, I get the message below.

Scotts-Mac-mini:seeding syacko$ go get gitlab.com/getsote/utilities/slogger
go get gitlab.com/getsote/utilities/slogger: module gitlab.com/getsote/utilities/slogger: git ls-remote -q origin in /Users/syacko/workspace/sotesoft/golang/pkg/mod/cache/vcs/80b3644beae1b986f1c659355360479e2463820660aa328d2edb1e571aba259b: exit status 128:
    remote: The project you were looking for could not be found.
    fatal: repository 'https://gitlab.com/getsote/utilities.git/' not found
Scotts-Mac-mini:seeding syacko$ 

The gitlab.com/getsote/utilities.git is a sub-directory and not a repository. I don't understand why go get is going to the utilities as a repository?

==========================

PREVIOUS Updates

Directory Structure:

GOPATH/src/slogger
              |----go.mod
              |----slogger.go
              |----slogger_test.go

go.mod file
module slogger  or  gitlab.com/getsote/utilities/slogger -> still gets the error below

go 1.14

gitlab.com/getsote/utilities contains repository slogger.git

I have run a test to see if the issue is the number of nodes in the path. So, I create a new repository with no sub-directory and pushed the slogger code. Then ran go get gitlab.com/getsote/slogger which generate a different error message.

GOPATH/gitlab.com/getsote/test-go-mod -> create new directory and added slogger files listed above

gitblab.com/getsote/test-go-mod -> new repository with one less level

Scotts-Mac-mini:test-go-mod syacko$ go get gitlab.com/getsote/test-go-mod
go: downloading gitlab.com/getsote/test-go-mod v0.0.0-20200409023538-794310bf7cf9
go get gitlab.com/getsote/test-go-mod: gitlab.com/getsote/test-go-mod@v0.0.0-20200409023538-794310bf7cf9: verifying module: gitlab.com/getsote/test-go-mod@v0.0.0-20200409023538-794310bf7cf9: reading https://sum.golang.org/lookup/gitlab.com/getsote/test-go-mod@v0.0.0-20200409023538-794310bf7cf9: 410 Gone
    server response:
    not found: gitlab.com/getsote/test-go-mod@v0.0.0-20200409023538-794310bf7cf9: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/7753c92c9bd1419156d8120684b7f3707fd207e01a2947ba89e2acfd2ecfb4d0: exit status 128:
        fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled
Scotts-Mac-mini:test-go-mod syacko$ 

This is still getting the status error of 128 for the missing version. Additionally, it is looking in the right location for the code. If this is true, then I just need help with the version missing. Moving to a shorted directory structure is doable.

========================

Newest Update

@praveent > The solution at https://medium.com/cloud-native-the-gathering/go-modules-with-private-git-repositories-dfe795068db4 didn't work for me. So I started from scratch to see how to resolve the issue.

S. Yacko
  • 386
  • 4
  • 14
  • 2
    Verify manually what gitlab reports. Read https://golang.org/cmd/go/#hdr-Remote_import_paths look for the go-get=1 stuff and try something like `curl "https://gitlab.com/getsote/utilities/slogger?go-get=1"` it should report back a meta-tag with the right information. One more: You are talking about a "module" but go get works in packages. Are you sure there is no mixup? – Volker Apr 08 '20 at 06:14
  • @Volker You should post this as an answer, not a comment. – dolmen Apr 08 '20 at 10:28
  • @Volker I'm using go.mod so module is correct. The module points to or contains the package. (See https://golang.org/doc/code.html#ImportingRemote). I have run the curl command it is reporting back `go get https://gitlab.com/getsote/utilities`, which is wrong, – S. Yacko Apr 08 '20 at 16:52
  • You should post you folder layout as it is still unclear how you group which packagaes into what maodules and how these are spread over repositories. – Volker Apr 09 '20 at 05:15

2 Answers2

1

The reason is because for a git repository it assumes that utilities is the repo and not utilities/slogger

There is a way to override this behavior by implementing go get API. But, gitlab is yet to implement the same due to security concerns. You can read more here. Gitlab issue

Update: Add reference to gitlab issue tracking this problem.

praveent
  • 562
  • 3
  • 10
  • Thank you for the reply and yes, I understand what is happening as I noted in my question. I want to know why and how to fix it. Your example is off a little. In your example, the gitbub.com/google/go-cmp/cmp would report that gitbub.com/google/go-cmp.git is not found versus the gitbub.com/google/go-cmp/cmp.git. – S. Yacko Apr 08 '20 at 16:55
  • 1
    It seems that this is a known issue. Check this - https://gitlab.com/gitlab-org/gitlab-foss/issues/30785. – praveent Apr 10 '20 at 06:38
  • Thank you for letting me know. I will just move to a new repository structure. Do you know anything about the version issue that I updated above? – S. Yacko Apr 10 '20 at 06:49
  • Is this a private repository that needs authentication to be able to clone or, download? If yes, please read the following post. https://medium.com/cloud-native-the-gathering/go-modules-with-private-git-repositories-dfe795068db4 You have two options. One with Personal access token or, another with ssh key. For ssh, ensure you don't add password to key. It will trigger lot of password requests with tooling. – praveent Apr 10 '20 at 10:34
  • @S.Yacko I will update answer if my suggestion above works. – praveent Apr 10 '20 at 10:39
0

So, here is how I got this to work using gitlab.com. I'm not saying other ways will not work, they just didn't for me and my setup. First, since I don't care if the code is available to the public, I created a new group at gitlab.com. This new group is public from the start, so no need to adjust permissions. Then I create a repository called packages and cloned the repository to my local machine with the same directory structure that is in gitlab.com, gitlab.com/soteapps/packages with ~/workspace/soteapps/packages on my machine. Both of these are out side the GOPATH. I'm not sure this matters, but it is working this way, so I'm putting it here.

Under packages, I copied the slogger directory and code.

cp -R slogger ~/workspace/soteapps/packages/.

Edited the go.mod file to match the repository structure, which is in the packages directory. There is no go.mod file in the slogger directory.

module gitlab.com/soteapps/packages

go 1.14

Edited the hello.go import to match the package.

package main

import (
    "fmt"
    "rsc.io/quote"
    "gitlab.com/soteapps/packages/slogger"
)

func main() {
    fmt.Println(quote.Hello())
    slogger.Info("Test message")
}

Built the program using go build -o hello and then ran it hello with the following results:

Scotts-Mac-mini:hello syacko$ hello
Hello, world.
INFO:2020/04/10 21:11:33 Test message
Scotts-Mac-mini:hello syacko$ 

Worked! Thank you all that helped. This wouldn't of gotten solved without your help.

Note: This only works for public repositories.

praveent
  • 562
  • 3
  • 10
S. Yacko
  • 386
  • 4
  • 14
  • Can you just one thing? See if similar structure works for private repos? I believe this might not work for private repos. – praveent Apr 12 '20 at 14:57
  • 1
    I did check this out over the weekend and it did not work for private repos. The issue with Gitlab reported here by you (Thank you so much) still is an issue. – S. Yacko Apr 13 '20 at 16:25