0

I have a golang application structure like this:

.
├── calc
│   ├── go.mod
│   ├── main.go
│   └── Makefile
├── go.mod
├── LICENSE
├── num
│   ├── go.mod
│   └── num.go
└── README.md

Where calc is an "application" where I'm importing the num package to add 2 numbers.

calc/go.mod

go 1.15

require github.com/github_username/goapp/num v0.2.1

num/go.mod

module github.com/github_username/goapp/num/v0.2.1

go 1.15

go.mod

module github.com/github_username/goapp/v0.2.1

go 1.15

When in /calc, and I run go run main.go, I get the following:

go: github.com/github_username/goapp/num@v0.2.1: reading github.com/github_username/goapp/num/num/go.mod at revision num/v0.2.1: unknown revision num/v0.2.1

What am I doing wrong? The github repo has the annotated tags.

For further context, I'm mimicking a production setup where we have six different mini golang services in folders such as calc, calc2, etc. where each "calc" service has a go.mod file.

Nona
  • 5,302
  • 7
  • 41
  • 79
  • 3
    Hi! You don't need go.mod inside of all those folders. Just the root one. – Jota Santos Feb 04 '21 at 05:22
  • 1
    Thanks, normally that makes sense, just added some more context – Nona Feb 04 '21 at 05:28
  • 1
    Alright, but I am not sure if I am getting it right. Anyway, `go mod edit -replace` might do what you need. With this, you can say that one particular module will be replaced by a folder (or even another repository). But again, `go.mod` inside of `go.mod` does make much sense. – Jota Santos Feb 04 '21 at 05:42
  • maybe that helps: https://stackoverflow.com/a/71617473/3025289 –  Mar 25 '22 at 13:09

2 Answers2

0

module github.com/github_username/goapp/num/v0.2.1

Is nonsense. The semver version tag "v0.2.1" does not belong into the module name. (Note that for major versions > 1, e.g. 4.3.1, the major version becomes part of the name like in module github.com/user/proj/folder/v4).

And one more: There are no source code belonging to the root go.mod so this module makes no sense whatsoever.

You really should not make that many modules.

Volker
  • 40,468
  • 7
  • 81
  • 87
0

Are you working with private repositories?

if yes, then you need to configure OAuth authentication:

export GITHUB_TOKEN=MY_GITHUB_TOKEN

git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"

Now, if you don't have the necessity to use private repositories!

Turn your repositories to the public that will solve the problem too.