1

I have a project to do at my job and we're using Bitbucket. So we have all our repos like this :

bitbucket.org/company/project Nothing new here.

I have created a repository called go-tools, his module name is bitbucket.org/company/go-tools and his path his bitbucket.org/company/go-tools

Following this medium post I could achieve a go mod tidy

package whatever

import (
       "bitbucket.org/company/go-tools"
       "bitbucket.org/company/go-tools/env"
       // and so on ...
)

The problem occurs when I try to replace "bitbucket.org/company" by "company.com" because we would like to have our company name instead bitbucket.

So my module name become company.com/go-tools instead of bitbucket.org/company/go-tools

And my imports become :

package whatever

import (
       "company.com/go-tools"
       "company.com/go-tools/env"
       // and so on ...
)

I have set my GOPRIVATE to use bitbucket and configured git to use bitbucket instead of company.com

git config --global url."https://{username}:{app password}@bitbucket.com/company".insteadOf "https://company.com"
go env -w GOPRIVATE=bitbucket.org/company 

And from there I only get a 404 error telling me that my package can't be found.

Did anyone have an idea why ? Am I misunderstanding something ?

NOTE : I also read this

Atelias
  • 31
  • 1
  • 5
  • do you run `go get` with `go mod download` in verbose mode? if yes - can you provide output? – Oleg Butuzov Mar 17 '21 at 09:52
  • Hi @OlegButuzov, thanx for your reply Here are the logs. It seems not even looking at bitbucket – Atelias Mar 17 '21 at 10:42
  • ?> go env GOPRIVATE bitbucket.org/company ?> go mod download -x company.com/go-tools@gomodtest # get https://proxy.golang.org/company.com/go-tools/@v/gomodtest.info # get https://proxy.golang.org/company.com/go-tools/@v/gomodtest.info: 410 Gone (0.129s) # get https://company.com/go-tools?go-get=1 # get https://company.com/go-tools?go-get=1: 404 Not Found (0.784s) go mod download: company.com/go-tools@gomodtest: unrecognized import path "company.com/go-tools": reading https://company.com/go-tools?go-get=1: 404 Not Found – Atelias Mar 17 '21 at 10:42
  • Use a `replace` directive in go.mod instead of using a redirect in your git config. – Adrian Mar 17 '21 at 15:55

1 Answers1

0

Thanks @adrian for your reply this answer my question for at least a part. I was more looking for a way of just go get 'company.com/whatever' but this is ok.

So if I understand correctly I need to go get bitbucket.org/company/whatever first and then go mod edit -replace bitbucket.org/company/whatever=company.com/whatever

Thanks

Atelias
  • 31
  • 1
  • 5
  • Hi @Atelias. did you find any solution to do ``go get company.com/whatever`` without using replace directive in go.mod ? – Shuvojit Saha Sep 22 '21 at 14:10