How to serve documentation using godoc together with go modules?

The issue isn’t modules so much as GOPATH. There’s a github issue thread that discusses this in more detail: https://github.com/golang/go/issues/26827 That thread has evolved a workaround that uses a docker container to run a godoc server with GOPATH set to the base of your dev tree. That godoc server will serve docs for all of … Read more

malformed module path “xxxx/xxxx/uuid” missing dot in first path element when migrating from GOPATH based dep to go mod

The go.mod file should be at the root of your project (in this case, my-api-server/go.mod). The first part of the module path should be a domain/path. For example, the full path might be github.com/your-github-username/my-api-server. The error you’re seeing is because the first part is not a domain (with a period). You don’t have to publish … Read more

Why there are two “require” blocks in go.mod since Go 1.17?

Because in Go 1.17 the module graph has been changed to enable pruning and lazy loading. The second require block contains indirect dependencies. https://golang.org/doc/go1.17#go-command If a module specifies go 1.17 or higher, the module graph includes only the immediate dependencies of other go 1.17 modules, not their full transitive dependencies. […] […] If a module … Read more

Manually fetch dependencies from go.mod?

It was an issue #26610, which is fixed now. So now you can just use: go mod download For this to work you need just the go.mod / go.sum files. For example, here’s how to have a cached multistage Docker build: (source) FROM golang:1.17-alpine as builder RUN apk –no-cache add ca-certificates git WORKDIR /build # … Read more

How to use a module that is outside of “GOPATH” in another module?

The easiest and working out-of-the-box solution is to put your database package / module into a VCS (e.g. github.com), so other packages (inside other modules) can simply refer to it by importing it like: import “github.com/someone/database” If you do so, you don’t even have to fiddle with the go.mod files manually, everything will be taken … Read more

what is the purpose of `go mod vendor` command?

Go Modules takes care of versioning, but it doesn’t necessarily take care of modules disappearing off the Internet or the Internet not being available. If a module is not available, the code cannot be built. Go Proxy will mitigate disappearing modules to some extent by mirroring modules, but it may not do it for all … Read more

What is the difference between go get command and go mod download command

Your module’s go.mod file records which versions of dependencies it requires. The source code for those dependencies is stored in a local cache. go get updates the requirements listed in your go.mod file. It also ensures that those requirements are self-consistent, and adds new requirements as needed so that every package imported by the packages … Read more