Go mod: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 15: Line 15:


=<tt>tidy</tt>=
=<tt>tidy</tt>=
Inspect the code, look for module imports, download them and update <code>go.mod</code>.
Inspect the code, look for module imports, recursively, download them and update <code>go.mod</code>. When <code>-v</code> is used, the command prints information about removed modules.
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
go mod tidy
go mod [-v] tidy
</syntaxhighlight>
</syntaxhighlight>


Line 26: Line 26:
consul "github.com/hashicorp/consul/api"
consul "github.com/hashicorp/consul/api"
)
)
...
...
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 17:55, 4 January 2024

Internal

Overview

go.mod

init

Initialize a v0 or v1 module:

go mod init example.com/m

Initialize a v2 module:

go mod init example.com/m/v2

tidy

Inspect the code, look for module imports, recursively, download them and update go.mod. When -v is used, the command prints information about removed modules.

go mod [-v] tidy

If we know our dependency, it is sufficient to add it to the import list, then execute go mod tidy:

import (
	consul "github.com/hashicorp/consul/api"
)
...