Go modules 441582151 3264840190 The go.mod, go.sum and friends. rc
- HOWTO Workspaces is a setup for multi-module repository Sourcing multiple modules in a single repository 3741742184 484254577
Init dependencies
go mod init your.tld/hello
cd path/to/module
cat > hello.go
package hello
func Hello() string {
return "Hello, world."
}
cat > hello_test.go
package hello
import "testing"
func TestHello(t *testing.T) {
want := "Hello, world."
if got := Hello(); got != want {
t.Errorf("Hello() = %q, want %q", got, want)
}
}
go test
go mod init your.tld/helloList all modules including dependencies
go list -m all
Adding dependency happens automatically
go test
GOPRIVATE=your.tld или GOPROXY="https://proxy.your.tld,direct"
Adding dependency from private git repository with non standard path,
for example your.tld/your/non/standard/dir/your-user/your-mod-nm
git config --global url."git@your.tld:your/non/standard/dir".insteadOf "https://your.tld/"
cd path/to/module
GOPRIVATE=your.tld go clean --modcache .
GOPRIVATE=your.tld go get -v -u your.tld/your-user/your-mod-nm
go testUpgrading dependency
go get -v -u your.tld/your-user/your-mod-nm@your-commit-hash-or-tag
Upgrading all dependencies
go get -u all
go mod tidy
go mod tidy compat=1.23
Test all packages sub directories
find . -name '*_test.go' -exec sh -c 'echo "{}" && cd $(dirname "{}") && go test' \;
Find out wrhere the dependence is used
go mod why -m
Removing/pruning unused dependencies
go mod tidy -v
This download does NOT match an earlier download recorded in go.sum.
go clean -modcache
TROUBLESHOOTING Gitlab private sub group module get error 1 [2}1965053761
- TEMP nginx proxy *
TROUBLESHOOTING Fatal: could not read Username for 'https://your.tld': terminal prompts disabled
$ cat >> ~/.gitconfig
[url "git@tyour.tld:"]
insteadOf = https://your.tld/
TROUBLESHOOTING Remote: ERROR: The project you were looking for could not be found or you don't have permission to view it
Maybe missing proxy?
GOPROXY=https://proxy.your.tld,https://proxy.golang.org,direct \
GOPRIVATE="" \
GOSUMDB="off" \
GONOSUMDB="*.your.tld" \
GONOPROXY="" \
go mod tidy