Skip to content

Latest commit

 

History

History
140 lines (88 loc) · 3.26 KB

File metadata and controls

140 lines (88 loc) · 3.26 KB

Go modules 441582151 3264840190 The go.mod, go.sum and friends. rc

Init

Init dependencies

go mod init your.tld/hello

Init (long)

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/hello

List

List all modules including dependencies

go list -m all

Add

Adding dependency happens automatically

go test

Private module url

GOPRIVATE=your.tld или GOPROXY="https://proxy.your.tld,direct"

Private/standard module url

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 test

Update

Upgrading dependency

go get -v -u your.tld/your-user/your-mod-nm@your-commit-hash-or-tag

Update all

Upgrading all dependencies

go get -u all
go mod tidy
go mod tidy compat=1.23

Testsing

Test all packages sub directories

find . -name '*_test.go' -exec sh -c 'echo "{}" && cd $(dirname "{}")  && go test' \;

Mod why

Find out wrhere the dependence is used

go mod why -m

Remove unused modules

Removing/pruning unused dependencies

go mod tidy -v

Mod checksum mismatch

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