-2

There is a private git site with address of gitlab.myownsite.com, and the folder structure in the way of:

/common
    |___ /libs
           |___ /lib_a
                  |__ lib_a.mod
/somethingelse

Notice that, this is NOT folder structure of single project, it is structure of gitlab.myownsite.com, which contain many repo in it. For example, I write a library lib_a by Go, then create a repo at path gitlab.myownsite.com/common/libs/lib_a, and its module name is:

module gitlab.myownsite.com/common/libs/lib_a

However, this naming disobeys the naming rule of github.com/username/reponame, which cause another project which use my lib_a by:

import "gitlab.myownsite.com/common/libs/lib_a"

incorrectly parse to import subpackage lib_a of gitlab.myownsite.com/common/libs.git, the common be recognized as username, libs as reponame, lib_a as packagename. go mod report error:

repository 'https://gitlab.myownsite.com/common/libs.git/' not found

I can not change the folder structure of this private gitlab site, how to solve this problem?

My go module env has: GOPRIVATE=gitlab.myownsite.com

jean
  • 2,825
  • 2
  • 35
  • 72
  • 1
    Do you have multiple modules? Where is the `go.mod` file? – icza Jan 18 '21 at 08:37
  • this gitlab is shared with many people. lib_x is independent project, however, they have same parent folder – jean Jan 18 '21 at 08:42
  • What are `lib_a.mod` and `lib_b.mod`? How do they relate to your Go code? Did you mean to put `go.mod` files in these locations, or is that something else? – Jonathan Hall Jan 18 '21 at 08:44
  • I'm not sure if your comment was meant to address @icza's question, but it doesn't. Do you have multiple modules? Where is the `go.mod` file? – Jonathan Hall Jan 18 '21 at 08:47
  • It's very unclear what problem you're trying to solve, but it may be related to GitLab subgroups limitations in private repos. There are some workarounds discussed [here](https://stackoverflow.com/q/56817601/13860) and [here](https://stackoverflow.com/q/29707689/13860). – Jonathan Hall Jan 18 '21 at 08:52
  • I redescribe my problem, hope that won't bring confusion – jean Jan 18 '21 at 09:01
  • 2
    Make sure your gitlab provides the necessary and relevant import meta headers. Read https://golang.org/cmd/go/#hdr-Remote_import_paths. Note that your assumtion that there is some kind of "naming rule of github.com/username/reponame" is plain wrong. There is no such thing. Some codehosting sites are known to the go tool, all other (especially yout Gitlab instance) has to provide the `` response. No need to change any folder layout. – Volker Jan 18 '21 at 10:41

1 Answers1

1

Thanks @Volker to point out, there is a meta info responsed when go get execute which describe which part of path is repo (the .git). Unfortunately, gitlab has a bug on it. I'm search a replace trick can avoid this problem. Or, last resort, re-structure gitlab path

jean
  • 2,825
  • 2
  • 35
  • 72