Questions tagged [go-modules]

A module is a collection of related Go packages. Modules are the unit of source code interchange and versioning. The go command has direct support for working with modules, including recording and resolving dependencies on other modules. Modules replace the old GOPATH-based approach to specifying which source files are used in a given build.

The Go Module concept was first published by Russ Cox here: Defining Go Modules.

Module support first appeared in Go 1.11 (in preliminary phase).

The go tool has built-in and extensive support for modules, documentation can be found at Go tool: Module maintenance and at Modules, module versions, and more. The command go help mod also provides sufficient details.

570 questions
20
votes
3 answers

Using "go get" to download binaries without adding them to go.mod

I'm using Go modules in my project and in my build system (e.g. Travis CI) I'm downloading a command-line utility (written in Go) with go get to assist with my build process, e.g.: go get github.com/mitchellh/gox However, this go get causes the…
ahmet alp balkan
  • 42,679
  • 38
  • 138
  • 214
20
votes
2 answers

How to fix Go build error "can't load package" with Go modules?

I'm setting up a new project using Go modules with this tutorial, and then trying to build it. The module is located in a folder outside of the $GOPATH with the following structure: example.com ├── my-project ├── ├── main ├── ├── ├── main.go ├── ├──…
Nicholas
  • 570
  • 1
  • 5
  • 15
19
votes
1 answer

Why does go.sum include so many older packages

I've been going though a set of projects, dealing with updating dependencies and there is one thing I don't have a clear answer to and that is why the generated sum file lists so many older versions of each dependency. in our project we had some…
Adam M.
  • 1,023
  • 1
  • 10
  • 21
19
votes
1 answer

How to identify dependency chain using Go Modules

How can I identify the import path of a module that exists in go.sum but not in go.mod? I'd like to know which module in go.mod is importing the module listed in go.sum, and the entire chain between them. I'm in the process of removing a deprecated…
Grokify
  • 15,092
  • 6
  • 60
  • 81
19
votes
3 answers

How to access nested modules (submodules) in Go?

Go version: 1.12.9 Here is the structure of a simple demo project: So we have a module domain, which contains two modules: activity and person. I would like to use domain with all nested modules in the main file => modules.go. I know how to import…
Hubert
  • 1,125
  • 5
  • 17
  • 36
19
votes
2 answers

go modules - replace does not work - replacement module without version must be directory path (rooted or starting with

I just want to use a local package using go modules. I have these files in a folder goweb: and go.mod module goweb go 1.12 require mypack v0.0.0 replace mypack => ./src/mypack But go.mod complains: replacement module without version must be…
Chris G.
  • 23,930
  • 48
  • 177
  • 302
19
votes
1 answer

Go Modules - naming convention of directories and packages

I understand Go Modules are yet an experimental opt-in feature, and perhaps because of that, I cannot find clear guidance on how to name directories and packages. In these Package names in Go Blog post and Package name in Effective Go, they talk…
Ryota
  • 1,157
  • 2
  • 11
  • 27
18
votes
4 answers

Go Modules importing issue in VSCode ("cannot find package [...] in any of [...]")

I'm encountering what probably seems to be a Gopls language server issue: All my external package import statements are being marked as incorrect when using Go Modules with the Go extension in VSCode. Here's exactly what I did so far: Inside my…
maxeth
  • 1,315
  • 1
  • 8
  • 17
18
votes
1 answer

Best way to use test dependencies in Go but prevent export them

Given a project in Golang (1.14+) which is using test dependencies (like github.com/stretchr/testify) and now assume this project is a public library which can be used by others. Usually when I now use go mod graph I'll always see this dependency…
GreNodge
  • 907
  • 4
  • 12
  • 26
18
votes
3 answers

Find version of a module

We are working with Go modules. I want in a CLI to get the specific version of a module. Is it possible? If you are curious, the reason is that I want to add the following generate command: //go:generate go run github.com/golang/mock/mockgen…
ElyashivLavi
  • 1,681
  • 3
  • 22
  • 33
17
votes
2 answers

Cannot determine module path for source directory

I have go.mod file inside root/src/abc. And in root/build-scripts I have a script which does go get. As I am using Go 1.11 I have not used the go path instead the mod file in root/src/abc takes care of other imports except for the packages that are…
Batman Rises
  • 319
  • 2
  • 5
  • 14
16
votes
1 answer

go: cannot find main module; see 'go help modules'

I recently started using Go. I installed go's extension on vscode and I can use some commands like go run and go build but when I run go test I get the following error: go: cannot find main module; see 'go help modules' although I have a *_test.go…
AliReda-M
  • 329
  • 1
  • 3
  • 12
16
votes
2 answers

Using subpackages with go mod locally

I have a go package located on my filesystem (not in the $GOPATH), called bitbucket.org/me/awesome. ~/awesome> tree . ├── main.go ├── go.mod ├── go.sum ├── subpackageA │   └── main.go My go.mod looks like: module bitbucket.org/me/awesome require…
atp
  • 30,132
  • 47
  • 125
  • 187
15
votes
1 answer

Content of go.sum and modules really used by a go application

I'm trying to compare the behavior of go mod tidy (and the resulting content of go.sum) to the output of go list -m all. Reading the docs, I understand go.sum contains the whole list of dependent modules declared in go.mod and in dependencies'…
new_bee
  • 211
  • 1
  • 2
  • 6
15
votes
1 answer

How to determine which module/s use an indirect dependency?

In Go 1.17 go.mod has two sections, direct dependencies and indirect dependencies, however, there is no indication how indirect dependencies are related to direct dependencies. How can I find out for a particuar indirect dependency what module or…
dimus
  • 8,712
  • 10
  • 45
  • 56
1 2
3
37 38