# Go 1.11: module tips WIP

# why

If it often helpful to find out why a package made its way into go.sum or go.mod. The command go mod why ... allows you find out what package(s) are importing the package you are querying about.

# Example

$ go mod why github.com/pborman/uuid
warning: ignoring symlink /Users/mbana/work/openbankinguk/bitbucket/conformance-suite/lib/server/web/dist
# github.com/pborman/uuid
bitbucket.org/openbankingteam/conformance-suite/proxy
github.com/go-openapi/strfmt
github.com/go-openapi/strfmt.test
github.com/pborman/uuid
1
2
3
4
5
6
7

# Documentation

$ go mod help why
usage: go mod why [-m] [-vendor] packages...

Why shows a shortest path in the import graph from the main module to
each of the listed packages. If the -m flag is given, why treats the
arguments as a list of modules and finds a path to any package in each
of the modules.

By default, why queries the graph of packages matched by "go list all",
which includes tests for reachable packages. The -vendor flag causes why
to exclude tests of dependencies.

The output is a sequence of stanzas, one for each package or module
name on the command line, separated by blank lines. Each stanza begins
with a comment line "# package" or "# module" giving the target
package or module. Subsequent lines give a path through the import
graph, one package per line. If the package or module is not
referenced from the main module, the stanza will display a single
parenthesized note indicating that fact.

For example:

	$ go mod why golang.org/x/text/language golang.org/x/text/encoding
	# golang.org/x/text/language
	rsc.io/quote
	rsc.io/sampler
	golang.org/x/text/language

	# golang.org/x/text/encoding
	(main module does not need package golang.org/x/text/encoding)
	$
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

# clean

To clean the module cache:

go clean -i -r -x -cache -testcache -modcache
1

# go mod help

To see all the available commands:

$ go mod help
Go mod provides access to operations on modules.

Note that support for modules is built into all the go commands,
not just 'go mod'. For example, day-to-day adding, removing, upgrading,
and downgrading of dependencies should be done using 'go get'.
See 'go help modules' for an overview of module functionality.

Usage:

	go mod <command> [arguments]

The commands are:

	download    download modules to local cache
	edit        edit go.mod from tools or scripts
	graph       print module requirement graph
	init        initialize new module in current directory
	tidy        add missing and remove unused modules
	vendor      make vendored copy of dependencies
	verify      verify dependencies have expected content
	why         explain why packages or modules are needed

Use "go help mod <command>" for more information about a command.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Last Updated: 1/24/2019, 10:27:56 AM