Search code examples
gogitlabgo-modules

Unable to create Go language packages in subdirectories of the repository


I have created repositories under multiple subdirectories on a private GitLab that contain Go language packages.

The hierarchy of the repository is below.

https://mygitlab.example.com/grand-parent-org/parent-org/child-org/myrepository.git

Also, the hierarchy of the library is below.

https://mygitlab.example.com/grand-parent-org/parent-org/child-org/myrepository/golib/go.mod

In this situation, I had initially assumed the package name as mygitlab.example.com/grand-parent-org/parent-org/child-org/myrepository/golib on go.mod in library, but could not successfully go get.

I tried the command.

go get mygitlab.example.com/grand-parent-org/parent-org/child-org/myrepository/golib

When executed, it will search for mygitlab.example.com/grand-parent-org.git and mygitlab.example.com/grand-parent-org/parent-org.git as repositories, but will not search deeper hierarchies as repositories by go get.

After various studies, we found that the library side go.mod, etc. can be used stably by setting it to mygitlab.example.com/grand-parent-org/parent-org/child-org/myrepository.git/golib When go get is done or as import of source code to use the library, it is written as follows.

import "mygitlab.example.com/grand-parent-org/parent-org/child-org/myrepository.git/golib"

  • Would this form of idea be inappropriate as a Go package operation?
  • I would like to know the best practices for creating go packages under further subdirectories in a repository that is under multiple subdirectories ?
  • I would like to know if there is a way to specify options for the hierarchy that the go language considers granting .git recursively ?
  • Currently, in this form, specifying a version in go.mod on the side that uses the library will fail. I would like to know if there is any useful way?

Solution

  • In GitLab, unauthenticated https access does not get to see deeper than the top-level group.

    Either don't use subgroups (GitHub work pretty well without) or use authentication.

    For the latter, read “Passing credentials to private repositories”.